Skip to content

Instantly share code, notes, and snippets.

@kindlychung
Created September 14, 2016 16:30
Show Gist options
  • Save kindlychung/09623fd469f089828ab0395871646e53 to your computer and use it in GitHub Desktop.
Save kindlychung/09623fd469f089828ab0395871646e53 to your computer and use it in GitHub Desktop.
#[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