Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct Scope<'a>
- {
- parent: Option<&'a mut Scope<'a>>,
- // Some data here
- }
- impl<'a> Scope<'a>
- {
- fn new() -> Scope<'a>
- {
- Scope {
- parent: None,
- }
- }
- fn child(&'a mut self) -> Scope<'a> // lifetimes here
- {
- Scope {
- parent: Some(self),
- }
- }
- }
- fn foo(scope: &mut Scope)
- {
- bar(scope);
- bar(scope);
- }
- fn bar(scope: &mut Scope)
- {
- scope.child();
- }
- fn main() -> () {
- let mut scope = Scope::new();
- foo(&mut scope);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement