pub struct WeakArcm<T: Clone> { /* private fields */ }Expand description
A weak reference wrapper for Arcm
Implementations§
Source§impl<T: Clone> WeakArcm<T>
impl<T: Clone> WeakArcm<T>
Sourcepub fn modify<F, R>(&self, f: F) -> Option<R>
pub fn modify<F, R>(&self, f: F) -> Option<R>
Attempts to modify the value if the original Arcm still exists
Examples found in repository?
examples/arcm_example.rs (line 22)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
fn main() {
let v = Arcm::new(42);
println!("v = {:?}", v);
println!("v.value() = {}", v.value());
v.modify(|x| *x += 1);
println!("v = {:?}", v);
println!("v.value() = {}", v.value());
v.modify(|x| *x *= 2);
println!("v = {:?}", v);
println!("v.value() = {}", v.value());
// Create a weak reference
let weak = v.downgrade();
println!("weak = {:?}", weak);
println!("weak.value() = {:?}", weak.value());
// Modify through weak reference
weak.modify(|x| *x += 10);
println!("After weak modify, v.value() = {}", v.value());
// Demonstrate what happens when strong reference is dropped
drop(v);
println!("After dropping strong ref, weak.value() = {:?}", weak.value());
// Examples of From and Into
println!("\n=== From and Into Examples ===");
// Using From
let v2 = Arcm::from(100);
println!("\nUsing From:");
println!("v2 = {:?}", v2);
println!("v2.value() = {}", v2.value());
// Using Into
let v3: Arcm<i32> = 200.into();
println!("\nUsing Into:");
println!("v3 = {:?}", v3);
println!("v3.value() = {}", v3.value());
// Using Into with String
let str_arcm: Arcm<String> = "Hello, World!".to_string().into();
println!("\nUsing Into with String:");
println!("str_arcm = {:?}", str_arcm);
println!("str_arcm.value() = {}", str_arcm.value());
// Using Into with Vec
let vec_arcm: Arcm<Vec<i32>> = vec![1, 2, 3].into();
println!("\nUsing Into with Vec:");
println!("vec_arcm = {:?}", vec_arcm);
println!("vec_arcm.value() = {:?}", vec_arcm.value());
}Sourcepub fn value(&self) -> Option<T>
pub fn value(&self) -> Option<T>
Attempts to get a copy of the value if the original Arcm still exists
Examples found in repository?
examples/arcm_example.rs (line 19)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
fn main() {
let v = Arcm::new(42);
println!("v = {:?}", v);
println!("v.value() = {}", v.value());
v.modify(|x| *x += 1);
println!("v = {:?}", v);
println!("v.value() = {}", v.value());
v.modify(|x| *x *= 2);
println!("v = {:?}", v);
println!("v.value() = {}", v.value());
// Create a weak reference
let weak = v.downgrade();
println!("weak = {:?}", weak);
println!("weak.value() = {:?}", weak.value());
// Modify through weak reference
weak.modify(|x| *x += 10);
println!("After weak modify, v.value() = {}", v.value());
// Demonstrate what happens when strong reference is dropped
drop(v);
println!("After dropping strong ref, weak.value() = {:?}", weak.value());
// Examples of From and Into
println!("\n=== From and Into Examples ===");
// Using From
let v2 = Arcm::from(100);
println!("\nUsing From:");
println!("v2 = {:?}", v2);
println!("v2.value() = {}", v2.value());
// Using Into
let v3: Arcm<i32> = 200.into();
println!("\nUsing Into:");
println!("v3 = {:?}", v3);
println!("v3.value() = {}", v3.value());
// Using Into with String
let str_arcm: Arcm<String> = "Hello, World!".to_string().into();
println!("\nUsing Into with String:");
println!("str_arcm = {:?}", str_arcm);
println!("str_arcm.value() = {}", str_arcm.value());
// Using Into with Vec
let vec_arcm: Arcm<Vec<i32>> = vec![1, 2, 3].into();
println!("\nUsing Into with Vec:");
println!("vec_arcm = {:?}", vec_arcm);
println!("vec_arcm.value() = {:?}", vec_arcm.value());
}Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for WeakArcm<T>
impl<T> RefUnwindSafe for WeakArcm<T>
impl<T> Send for WeakArcm<T>where
T: Send,
impl<T> Sync for WeakArcm<T>where
T: Send,
impl<T> Unpin for WeakArcm<T>
impl<T> UnwindSafe for WeakArcm<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more