arcm_example/
arcm_example.rs

1use sovran_arc::arcm::Arcm;
2
3fn main() {
4    let v = Arcm::new(42);
5    println!("v = {:?}", v);
6    println!("v.value() = {}", v.value());
7
8    v.modify(|x| *x += 1);
9    println!("v = {:?}", v);
10    println!("v.value() = {}", v.value());
11
12    v.modify(|x| *x *= 2);
13    println!("v = {:?}", v);
14    println!("v.value() = {}", v.value());
15
16    // Create a weak reference
17    let weak = v.downgrade();
18    println!("weak = {:?}", weak);
19    println!("weak.value() = {:?}", weak.value());
20
21    // Modify through weak reference
22    weak.modify(|x| *x += 10);
23    println!("After weak modify, v.value() = {}", v.value());
24
25    // Demonstrate what happens when strong reference is dropped
26    drop(v);
27    println!(
28        "After dropping strong ref, weak.value() = {:?}",
29        weak.value()
30    );
31
32    // Examples of From and Into
33    println!("\n=== From and Into Examples ===");
34
35    // Using From
36    let v2 = Arcm::from(100);
37    println!("\nUsing From:");
38    println!("v2 = {:?}", v2);
39    println!("v2.value() = {}", v2.value());
40
41    // Using Into
42    let v3: Arcm<i32> = 200.into();
43    println!("\nUsing Into:");
44    println!("v3 = {:?}", v3);
45    println!("v3.value() = {}", v3.value());
46
47    // Using Into with String
48    let str_arcm: Arcm<String> = "Hello, World!".to_string().into();
49    println!("\nUsing Into with String:");
50    println!("str_arcm = {:?}", str_arcm);
51    println!("str_arcm.value() = {}", str_arcm.value());
52
53    // Using Into with Vec
54    let vec_arcm: Arcm<Vec<i32>> = vec![1, 2, 3].into();
55    println!("\nUsing Into with Vec:");
56    println!("vec_arcm = {:?}", vec_arcm);
57    println!("vec_arcm.value() = {:?}", vec_arcm.value());
58}