Struct bacon_rajan_cc::Cc
[−]
[src]
pub struct Cc<T: 'static + Trace> { // some fields omitted }
A reference-counted pointer type over an immutable value.
See the module level documentation for more details.
Methods
impl<T: Trace> Cc<T>
fn new(value: T) -> Cc<T>
fn downgrade(&self) -> Weak<T>
Downgrades the Cc<T>
to a Weak<T>
reference.
Examples
use bacon_rajan_cc::Cc; let five = Cc::new(5); let weak_five = five.downgrade();
impl<T: 'static + Trace> Cc<T>
fn is_unique(&self) -> bool
Returns true if there are no other Cc
or Weak<T>
values that share
the same inner value.
Examples
use bacon_rajan_cc; use bacon_rajan_cc::Cc; let five = Cc::new(5); assert_eq!(five.is_unique(), true); let another_five = five.clone(); assert_eq!(five.is_unique(), false); assert_eq!(another_five.is_unique(), false);
fn try_unwrap(self) -> Result<T, Cc<T>>
Unwraps the contained value if the Cc<T>
is unique.
If the Cc<T>
is not unique, an Err
is returned with the same Cc<T>
.
Examples
use bacon_rajan_cc::Cc; let x = Cc::new(3); assert_eq!(x.try_unwrap(), Ok(3)); let x = Cc::new(4); let _y = x.clone(); assert_eq!(x.try_unwrap(), Err(Cc::new(4)));
fn get_mut(&mut self) -> Option<&mut T>
Returns a mutable reference to the contained value if the Cc<T>
is
unique.
Returns None
if the Cc<T>
is not unique.
Examples
use bacon_rajan_cc::Cc; let mut x = Cc::new(3); *Cc::get_mut(&mut x).unwrap() = 4; assert_eq!(*x, 4); let _y = x.clone(); assert!(Cc::get_mut(&mut x).is_none());
fn strong_count(&self) -> usize
Get the number of strong references to this value.
fn weak_count(&self) -> usize
Get the number of weak references to this value.
impl<T: 'static + Clone + Trace> Cc<T>
fn make_unique(&mut self) -> &mut T
Make a mutable reference from the given Cc<T>
.
This is also referred to as a copy-on-write operation because the inner data is cloned if the reference count is greater than one.
Examples
use bacon_rajan_cc::Cc; let mut five = Cc::new(5); let mut_five = five.make_unique();