RefCounted

Trait RefCounted 

Source
pub trait RefCounted<T>:
    Sized
    + Clone
    + Deref<Target = T>
    + From<T> {
    // Required methods
    fn get_mut(&mut self) -> Option<&mut T>;
    fn make_mut(&mut self) -> &mut T
       where T: Clone;
}
Expand description

A convenience trait to abstract over Arc and Rc APIs.

Required Methods§

Source

fn get_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the contained value if the wrapper has a single, unique, reference.

Returns None if this is not the only reference to the data.

Source

fn make_mut(&mut self) -> &mut T
where T: Clone,

Make a mutable reference into the given implementation. If the implementation has more than one strong reference, or any weak references, the inner data is cloned.

This is also referred to as a copy-on-write.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> RefCounted<T> for Rc<T>

Source§

fn get_mut(&mut self) -> Option<&mut T>

Source§

fn make_mut(&mut self) -> &mut T
where T: Clone,

Source§

impl<T> RefCounted<T> for Arc<T>

Source§

fn get_mut(&mut self) -> Option<&mut T>

Source§

fn make_mut(&mut self) -> &mut T
where T: Clone,

Implementors§