Skip to content

Instantly share code, notes, and snippets.

@domluna
Created August 28, 2013 16:34
Show Gist options
  • Save domluna/6368107 to your computer and use it in GitHub Desktop.
Save domluna/6368107 to your computer and use it in GitHub Desktop.
struct Foo<'self> {
name: ~str,
ref_bar: &'self Bar // Bar lives as long as Foo
// When Foo is freed, Bar is freed
// No memory leaks!
}
struct Bar {
name: ~str
}
impl Foo {
// The ref name is valid with the lifetime of Foo
// if Foo is freed so is the ref_name
fn get_ref_name<'r> (&'r self) -> &'r~str {
&self.name
}
}
fn main() {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment