Guest User

Untitled

a guest
Jun 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. struct Planet<T> {
  2. i: T
  3. }
  4.  
  5. trait Spinner<T> {
  6. fn spin(&self, value: T);
  7. }
  8.  
  9. impl<T> Spinner<T> for Planet<T> {
  10. fn spin(&self, _value: T) {}
  11. }
  12.  
  13.  
  14. // foo2 fails: Due to lifetime of local variable being less than 'a
  15.  
  16. fn foo2<'a>(t: &'a Spinner<&'a i32>) {
  17. let x: i32 = 10;
  18. t.spin(&x);
  19. }
  20.  
  21.  
  22. // foo1 passes: But here also the lifetime of local variable is less than 'a?
  23.  
  24. fn foo1<'a>(t: &'a Planet<&'a i32>) {
  25. let x: i32 = 10;
  26. t.spin(&x);
  27. }
  28.  
  29. fn main() {}
Add Comment
Please, Sign In to add comment