Skip to content

Instantly share code, notes, and snippets.

@steveklabnik
Forked from anonymous/playground.rs
Last active August 9, 2016 15:29
Show Gist options
  • Save steveklabnik/b258d64bd81f734fc07909fbc491d12a to your computer and use it in GitHub Desktop.
Save steveklabnik/b258d64bd81f734fc07909fbc491d12a 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,
}
impl<'a> Thing<'a> {
fn new(lib: &'a Lib) -> Thing {
Thing {
lib_obj: lib,
}
}
fn lib_widget(&self) -> &LibWdiget {
self.get_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