simple/simple.rs
1use ref_kman::Ref;
2
3fn main() {
4 let data = Ref::new(0);
5
6 {
7 let mut mut_data = data.get_mut();
8 println!("Is locked: {}", data.locked());
9
10 *mut_data = 21;
11 }
12
13 // Dont do this if you do this the current thread will be stuck in a loop because noting will be droped to unlock;
14 //let mut mut_data = data.get_mut();
15 //let mut seccond_mut_data = data.get_mut();
16
17 //Never do:
18 // data.lock()
19 // data.unlock()
20 // this is very bed!
21 // do this if you really know what are you doing
22
23 let data2 = data.clone();
24 // data2 is not only the value but is has the same pointer
25 // if data2 is modificated will be applied to data
26
27 data2.mut_scope(|value| {
28 *value = 33;
29 });
30
31 // when all ref will be droped, then the data will be droped!
32
33 println!("Simple: {}", data);
34}