Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. fn consume_with_relish<F>(func: F)
  2. where F: FnOnce() -> String
  3. {
  4. // `func` consumes its captured variables, so it cannot be run more
  5. // than once.
  6. println!("Consumed: {}", func());
  7. //println!("Consumed: {}", func());
  8.  
  9. println!("Delicious!");
  10.  
  11. // Attempting to invoke `func()` again will throw a `use of moved
  12. // value` error for `func`.
  13. }
  14.  
  15.  
  16.  
  17.  
  18. fn main() {
  19.  
  20. enivronment();
  21.  
  22. let x = String::from("x");
  23. let consume_and_return_x = move || x;
  24. consume_with_relish(consume_and_return_x);
  25. //consume_with_relish(consume_and_return_x);
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement