January 2019
Intermediate to advanced
520 pages
14h 32m
English
serde_derive maps names of fields in the code to fields of data. For example, the title field of a struct will expect the title field of a data object. If the protocol uses other names for fields, you have to take this into account to avoid warnings. For example, a struct in a protocol might contain the stdDev field, but if you use the name of this field in Rust, you get the following warning:
warning: variable `stdDev` should have a snake case name such as `std_dev`
You can fix this adding the #![allow(non_snake_case)] attribute, but this makes the code unsightly. A better solution is to use the #[serde(rename="stdDev")] attribute and use the other naming convention for serialization and deserialization only.
Read now
Unlock full access