Complete the code to declare a struct with a lifetime parameter.
struct Book<[1]> { title: &[1] str, }
The lifetime parameter 'a is used to tell Rust how long the reference inside the struct lives.
Complete the code to implement a method that returns the title reference.
impl<[1]> Book<[1]> { fn get_title(&self) -> &[1] str { self.title } }
The lifetime 'a must be consistent in the impl block and the method return type to ensure the reference is valid.
Fix the error by adding the correct lifetime to the struct field.
struct Person {
name: &[1] str,
}References in structs must have explicit lifetimes. Using 'static means the reference lives for the entire program.
Fill both blanks to create a struct with two references having the same lifetime.
struct Pair<[1]> { first: &[1] str, second: &[2] str, }
Both references must share the same lifetime 'a to ensure they live as long as the struct.
Fill all three blanks to define a struct with a lifetime and implement a method returning a reference.
struct Message<[1]> { content: &[2] str, } impl<[3]> Message<[3]> { fn content(&self) -> &[3] str { self.content } }
The lifetime 'a must be declared and used consistently in the struct and impl blocks, and in the method signature.