Created
August 28, 2013 16:34
-
-
Save domluna/6368107 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
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