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>

Constructs a new Cc<T>.

Examples

use bacon_rajan_cc::Cc;

let five = Cc::new(5);

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();

Trait Implementations

impl<T: Trace> Deref for Cc<T>

type Target = T

fn deref(&self) -> &T

impl<T: Trace> Drop for Cc<T>

fn drop(&mut self)

impl<T: Trace> Clone for Cc<T>

fn clone(&self) -> Cc<T>

fn clone_from(&mut self, source: &Self)

impl<T: Default + Trace> Default for Cc<T>

fn default() -> Cc<T>

impl<T: PartialEq + Trace> PartialEq for Cc<T>

fn eq(&self, other: &Cc<T>) -> bool

fn ne(&self, other: &Cc<T>) -> bool

impl<T: Eq + Trace> Eq for Cc<T>

impl<T: PartialOrd + Trace> PartialOrd for Cc<T>

fn partial_cmp(&self, other: &Cc<T>) -> Option<Ordering>

fn lt(&self, other: &Cc<T>) -> bool

fn le(&self, other: &Cc<T>) -> bool

fn gt(&self, other: &Cc<T>) -> bool

fn ge(&self, other: &Cc<T>) -> bool

impl<T: Ord + Trace> Ord for Cc<T>

fn cmp(&self, other: &Cc<T>) -> Ordering

impl<T: Hash + Trace> Hash for Cc<T>

fn hash<H: Hasher>(&self, state: &mut H)

fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher

impl<T: Display + Trace> Display for Cc<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<T: Debug + Trace> Debug for Cc<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<T: Trace> Pointer for Cc<T>

fn fmt(&self, f: &mut Formatter) -> Result

impl<T: Trace> Trace for Cc<T>

fn trace(&mut self, tracer: &mut Tracer)