SHARE
TWEET

Untitled

a guest Jul 17th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct Scope<'a>
  2. {
  3.     parent: Option<&'a mut Scope<'a>>,
  4.     // Some data here
  5. }
  6.  
  7. impl<'a> Scope<'a>
  8. {
  9.     fn new() -> Scope<'a>
  10.     {
  11.         Scope {
  12.             parent: None,
  13.         }
  14.     }
  15.  
  16.     fn child(&'a mut self) -> Scope<'a> // lifetimes here
  17.     {
  18.         Scope {
  19.             parent: Some(self),
  20.         }
  21.     }
  22. }
  23.  
  24. fn foo(scope: &mut Scope)
  25. {
  26.     bar(scope);
  27.     bar(scope);
  28. }
  29.  
  30. fn bar(scope: &mut Scope)
  31. {
  32.     scope.child();
  33. }
  34.  
  35. fn main() -> () {
  36.     let mut scope = Scope::new();
  37.    
  38.     foo(&mut scope);
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top