rustlings

solving rustlings ft. dracuxan
git clone [email protected]:dracuxan/rustlings.git
Log | Files | Refs

lifetimes3.rs (324B)


      1 // Lifetimes are also needed when structs hold references.
      2 
      3 // TODO: Fix the compiler errors about the struct.
      4 struct Book<'a> {
      5     author: &'a str,
      6     title: &'a str,
      7 }
      8 
      9 fn main() {
     10     let book = Book {
     11         author: "George Orwell",
     12         title: "1984",
     13     };
     14 
     15     println!("{} by {}", book.title, book.author);
     16 }