| 1 | use enclose::enclose; |
| 2 | |
| 3 | fn main() { |
| 4 | let mut clone_data = 2; |
| 5 | my_enclose(enclose!((ref clone_data => mut ref_clone_data) || { |
| 6 | // (ref clone_data => mut ref_clone_data) -> |
| 7 | // let ref mut ref_clone_data = clone_data; |
| 8 | |
| 9 | println!("#0 {:?}", ref_clone_data); |
| 10 | *ref_clone_data += 2; |
| 11 | println!("#1 {:?}", clone_data); |
| 12 | |
| 13 | assert_eq!(clone_data, 4); |
| 14 | })); |
| 15 | |
| 16 | assert_eq!(clone_data, 4); |
| 17 | } |
| 18 | |
| 19 | #[inline] |
| 20 | fn my_enclose<F: FnOnce() -> R, R>(a: F) -> R { |
| 21 | a() |
| 22 | } |