Skip to content

Instantly share code, notes, and snippets.

Created August 9, 2016 15:11
Show Gist options
  • Save anonymous/5bf670bd47556d608144b461165185e5 to your computer and use it in GitHub Desktop.
Save anonymous/5bf670bd47556d608144b461165185e5 to your computer and use it in GitHub Desktop.
Shared via Rust Playground
struct Lib {
// whatever... but it implements Drop
}
impl Lib {
fn get_widget() -> &LibWidget {
// unimportant (I think), but LibWidget implements Drop
}
}
struct Thing<'a> {
lib_obj: &'a Lib,
lib_widget: &'a LibWidget,
}
impl<'a> Thing<'a> {
fn new(lib: &'a Lib) -> Thing {
let widget = lib.get_widget();
Thing {
lib_obj: lib,
lib_widget: widget,
}
}
}
fn main() {
let lib = Lib::new();
let thing = Thing::new(&lib);
// do stuff with thing...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment