Guest User

Untitled

a guest
Oct 18th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. // ---------FnMut trait
  2. fn main() {
  3. let mut s = "rush".to_string();
  4. {
  5. let mut c = ||{ s += " rust" };
  6. c();
  7. c();
  8. // error: cannot borrow `s` as immutable
  9. // because it is also borrowed as mutable
  10. // println!("{:?}", s);
  11. }
  12. println!("{:?}", s);
  13. }
  14.  
  15. // --------- Fn trait
  16.  
  17. // fn main() {
  18. // let s = "hello";
  19. // let c = ||{ println!("{:?}", s) };
  20. // c();
  21. // c();
  22. // println!("{:?}", s);
  23. // }
  24.  
  25. // -------------- Fn trait
  26. // fn main() {
  27. // let s = "hello";
  28. // let c = move ||{ println!("{:?}", s) };
  29. // c();
  30. // c();
  31. // println!("{:?}", s);
  32. // }
  33.  
  34. // fn main() {
  35. // let s = "hello".to_string();
  36. // let c = move ||{ println!("{:?}", s) };
  37. // c();
  38. // c();
  39. // // println!("{:?}", s); // error: use of moved value: `s`
  40. // }
  41.  
  42. // ------------- FnOnce triat
  43. // fn main() {
  44. // let s = "hello".to_string();
  45. // let c = || s;
  46. // c();
  47. // // c(); // error: use of moved value: `c`
  48. // // println!("{:?}", s); // error: use of moved value: `s`
  49. // }
  50.  
  51. // ---------------- Fn trait
  52. // fn main() {
  53.  
  54. // let c = ||{ println!("hhh") };
  55. // }
Add Comment
Please, Sign In to add comment