January 2019
Intermediate to advanced
520 pages
14h 32m
English
The main struct is Unicorn, which contains the creature we will ride:
#[derive(Clone, Serialize)] #[serde(rename_all = "PascalCase")] struct Unicorn { name: String, color: String, gender: String, }
Every Unicorn has a name, color, and gender. We will store these values as items in a DynamoDB record. To simplify the creation of the instance in the code, we will add the following constructor:
impl Unicorn { fn new(name: &str, color: &str, gender: &str) -> Self { Unicorn { name: name.to_owned(), color: color.to_owned(), gender: gender.to_owned(), } } }
You may ask why we don't represent color and gender with enumerations. It's possible, but you have to be sure that the serialized values are exactly what you want.
Read now
Unlock full access