The fn keyword (pronounced “fun”) introduces a function.
The mut keyword (pronounced “mute) is short for mutable.
A &str (pronounced “stir” or “string slice”) is a reference to a run of UTF-8 text owned by someone else: it “borrows” the text.
A value of type &String (pronounced “ref String”) is a reference to a String value.
The expression &e yields a shared reference to e’s value; if e has the type T, then &e has the type &T, pronounced “ref T.”
The expression &mut e yields a mutable reference to e’s value; you write its type as &mut T, which is pronounced “ref mute T.”
Read the <T> after the type name as “for any type T.”
| |
Read the <T: FromStr> as “For any type T that implements the FromStr trait…”.
| |
The lifetime 'a (pronounced “tick A”) is a lifetime parameter of f. Read <'a> as “for any lifetime 'a”. So when we write fn f<'a>(p: &'a i32), we’re defining a function that takes a reference to an i32 with any given lifetime 'a.
| |
Read the <T> in Queue<T> as “for any element type T…”. So this definition reads, “For any type T, a Queue<T> is two fields of type Vec<T>.”
| |
Read the line impl<T> Queue<T> as something like, “for any type T, here are some associated functions available on Queue<T>.” Then, you can use the type parameter T as a type in the associated function definitions.
| |