O'Reilly logo

Mastering Rust by Vesa Kaihlavirta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Impl signatures

When we create impl blocks for structs with references, we need to repeat the lifetime declarations and definitions again. For instance, if we made an implementation for the Foo struct we defined previously, the syntax would look like this:

// lifetime-structs.rs impl<'a> Number<'a> {     fn get_the_number(&self) -> &'a u8 {         self.num     }      fn set_the_number(&mut self, new_number: &'a u8) {    self.num = new_number } 

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required