Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn consume_with_relish<F>(func: F)
- where F: FnOnce() -> String
- {
- // `func` consumes its captured variables, so it cannot be run more
- // than once.
- println!("Consumed: {}", func());
- //println!("Consumed: {}", func());
- println!("Delicious!");
- // Attempting to invoke `func()` again will throw a `use of moved
- // value` error for `func`.
- }
- fn main() {
- enivronment();
- let x = String::from("x");
- let consume_and_return_x = move || x;
- consume_with_relish(consume_and_return_x);
- //consume_with_relish(consume_and_return_x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement