Created
September 14, 2016 16:30
-
-
Save kindlychung/09623fd469f089828ab0395871646e53 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 Foo { | |
f : i32 | |
} | |
#[derive(Debug)] | |
struct Bar<'b> { | |
bar1 : &'b Foo, | |
bar2 : &'b Foo | |
} | |
#[allow(unused_variables)] | |
fn makeBar<'b>(foo1: &'b Foo, foo2: &'b Foo) -> Bar<'b> { | |
Bar { bar1 : foo1, bar2 : foo2 } | |
} | |
fn extractBar2<'a>(foo: &'a Foo) -> &'a Foo { | |
let foo1 = Foo { f : 22 }; | |
let foo2 = makeBar(&foo, &foo1).bar1; | |
foo2 | |
} | |
fn main() { | |
let foo = Foo { f : 11 }; | |
let foo1 = extractBar2(&foo); | |
println!("foo1: {:?}", foo1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment