Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumRustlifetimes and elisionSingle-choice MCQ

A struct stores a borrowed slice. Lifetime elision applies the third rule (the `&self` lifetime) to the method below. What does the elided signature force, and does `main` compile?

struct Parser<'a> { data: &'a str } impl<'a> Parser<'a> { fn get(&self) -> &str { self.data } } fn main() { let s = String::from("xyz"); let out; { let p = Parser { data: &s }; out = p.get(); } println!("{}", out); }