with_closure/
with_closure.rs

1use ref_kman::Ref;
2
3fn main() {
4    let data = Ref::new(0);
5
6    /// in this scope can be modificated
7    data.mut_scope(|data| {
8        *data = 21;
9    });
10
11    println!("Data: {}", data);
12    assert_eq!(*data, 21);
13
14    let a = 43;
15    /// if you want to move a variabile to closure you need to make a other variabile a reference and put that
16    let tmp_a = &a;
17    ///move is to move the tmp_a to closure, this is why you dont want to move the original value because will be droped when closure ends!
18    data.mut_scope(move |data| {
19        let a = tmp_a;
20        *data = *a;
21    });
22
23    println!("{}", data);
24    assert_eq!(*data, a);
25}