October 2018
Beginner
180 pages
4h 48m
English
Traits don't exist independently; they are something that data types have. So, the first thing we need to do is create data types to represent the various kinds of driving directions:
pub struct Forward { pub blocks: u8,}pub struct Turn { pub slight: bool, pub right: bool,}pub struct Stop {}
These structures contain the same information that we included in the enumeration parameters before. The Stop structure is interesting, because it's empty. It stores no information at all. Its only purpose is to be a data type.
Now, we have a trait and we have data types, but so far they are not related in any way. Let's implement ...
Read now
Unlock full access