Created
September 30, 2022 00:20
-
-
Save dmezh/dbc2429762005660ec0dec287a0180a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[derive(Debug)] | |
struct I; | |
struct J { | |
things: Vec<I>, | |
} | |
impl J { | |
pub fn new() -> Self { | |
J { things: Vec::new() } | |
} | |
pub fn add_to_things(&mut self, thing: I) -> &I { | |
let idx = self.things.len(); | |
self.things.push(thing); | |
&self.things[idx] | |
} | |
} | |
fn main() { | |
let mut s = J::new(); | |
let thing_inserted = s.add_to_things(I {}); // lifetime of this borrow extended to line 28? | |
let thing_inserted2 = s.add_to_things(I {}); | |
println!("{:#?}", thing_inserted); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment