Module yewdux::mrc

source ·
Expand description

Mutable reference counted wrapper type that works well with Yewdux.

Useful when you don’t want to implement Clone or PartialEq for a type.

let expensive_data = Mrc::new("Some long string that shouldn't be cloned.".to_string());
let old_ref = expensive_data.clone();

// They are equal (for now).
assert!(expensive_data == old_ref);

// Here we use interior mutability to change the inner value. Doing so will mark the
// container as changed.
*expensive_data.borrow_mut() += " Here we can modify our expensive data.";

// Once marked as changed, it will cause any equality check to fail (forcing a re-render).
assert!(expensive_data != old_ref);
// The underlying state is the same though.
assert!(*expensive_data.borrow() == *old_ref.borrow());

Structs

  • Mutable reference counted wrapper type that works well with Yewdux.