Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement