January 2019
Intermediate to advanced
520 pages
14h 32m
English
In our example, we want to have two fields in a serialized data form: distribution and parameters. In the first field, we want to hold a variant of enumeration, but renamed so that it's in lowercase. In the second field, we'll keep the parameters of the specific variant.
To achieve this, you can write your own Serializer and Deserializer, an approach that we'll explore later in this chapter. For this case, however, we can use the #[serde(tag = "...")] and #[serde(context = "...")] attributes. context can only be used in a pair with tag.
We have added this to our RngRequest:
#[serde(tag = "distribution", content = "parameters", rename_all = "lowercase")]
This attribute specifies the distribution
Read now
Unlock full access