Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ---------FnMut trait
- fn main() {
- let mut s = "rush".to_string();
- {
- let mut c = ||{ s += " rust" };
- c();
- c();
- // error: cannot borrow `s` as immutable
- // because it is also borrowed as mutable
- // println!("{:?}", s);
- }
- println!("{:?}", s);
- }
- // --------- Fn trait
- // fn main() {
- // let s = "hello";
- // let c = ||{ println!("{:?}", s) };
- // c();
- // c();
- // println!("{:?}", s);
- // }
- // -------------- Fn trait
- // fn main() {
- // let s = "hello";
- // let c = move ||{ println!("{:?}", s) };
- // c();
- // c();
- // println!("{:?}", s);
- // }
- // fn main() {
- // let s = "hello".to_string();
- // let c = move ||{ println!("{:?}", s) };
- // c();
- // c();
- // // println!("{:?}", s); // error: use of moved value: `s`
- // }
- // ------------- FnOnce triat
- // fn main() {
- // let s = "hello".to_string();
- // let c = || s;
- // c();
- // // c(); // error: use of moved value: `c`
- // // println!("{:?}", s); // error: use of moved value: `s`
- // }
- // ---------------- Fn trait
- // fn main() {
- // let c = ||{ println!("hhh") };
- // }
Add Comment
Please, Sign In to add comment