pub struct ToDo {
    pub id: i32,
    pub complete: bool,
    pub action: String,
}

This struct will represent a ToDo item, it should look similar to the json definition in our original spec.

  • id - i32: This will be our numeric id
  • complete - bool: This will be true or false depending on if the action was completed
  • action - String: This will be the text describing our action

You might have noticed that the id property's type is i32 rust requires you not only label number types as numbers but with a more specific definition. All of the number types start with either the letter i (integer, positive or negative whole number), u (unsigned integer, always positive whole number) or f (floating point, number with a decimal) followed by their "bit-ness". Currently for i and u these include 8, 16, 32, 64 and 128 while for f it would either be 32 and 64.

impl ToDo {
    /// can be used like this 
    /// ```
    /// let todo = ToDo::new(String::from("thing"))
    /// ```
    pub fn new(action: String) -> ToDo {
        ToDo {
            id: -1,
            complete: false,
            action: action,
        }
    }
}

ToDo also has an impl block defining 1 function which will act as a convenience constructor for brand new ToDos. This function takes 1 arguments a string describing the action and will set the id to -1 and complete to false.