Debian Codegraph @

examples/expr.rs

raw symbols SCIP
1 use enclose::enclose;
2 use std::sync::Arc;
3
4 fn main() {
5 let clone_data = Arc::new(0);
6 let add_data = Arc::new(100);
7
8 // I also note that any expressions can be used, but the main thing is to
9 // put the @ symbol at the beginning of the variable, and not forget to assign
10 // a new name to the variable using =>.
11 my_enclose(
12 enclose!((@*clone_data => mut clone_data: usize, @*(add_data.clone()) => add_data,) || {
13 // (@*clone_data => mut clone_data, @*(add_data.clone()) => add_data) ->
14 // let mut clone_data = *clone_data;
15 // let add_data = *(add_data.clone());
16
17 println!("#0 {:?}", clone_data);
18 clone_data += add_data;
19 println!("#1 {:?}", clone_data);
20
21 assert_eq!(clone_data, 100);
22 }),
23 );
24
25 assert_eq!(*clone_data, 0);
26 }
27
28 #[inline]
29 fn my_enclose<F: FnOnce() -> R, R>(a: F) -> R {
30 a()
31 }