Last active
September 30, 2022 00:33
-
-
Save dmezh/3359b72c40dfaf943337cfb46c70f67b to your computer and use it in GitHub Desktop.
This file contains hidden or 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] | |
} | |
pub fn get_thing(&self) -> &I { | |
return &self.things[0]; | |
} | |
} | |
fn main() { | |
let mut s = J::new(); | |
let thing_inserted = s.add_to_things(I {}); // lifetime of this borrow extended to line 32? | |
let thing_back = s.get_thing(); // does not compile | |
println!("{:#?}", thing_inserted); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment