[][src]Struct bacon_rajan_cc::Cc

pub struct Cc<T: 'static + Trace> { /* 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>[src]

pub fn new(value: T) -> Cc<T>[src]

Constructs a new Cc<T>.

Examples

use bacon_rajan_cc::Cc;

let five = Cc::new(5);

pub fn downgrade(&self) -> Weak<T>[src]

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>[src]

pub fn is_unique(&self) -> bool[src]

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

pub fn try_unwrap(self) -> Result<T, Cc<T>>[src]

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

pub fn get_mut(&mut self) -> Option<&mut T>[src]

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

pub fn strong_count(&self) -> usize[src]

Get the number of strong references to this value.

pub fn weak_count(&self) -> usize[src]

Get the number of weak references to this value.

impl<T: 'static + Clone + Trace> Cc<T>[src]

pub fn make_unique(&mut self) -> &mut T[src]

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> Trace for Cc<T>[src]

impl<T: Trace> Clone for Cc<T>[src]

fn clone(&self) -> Cc<T>[src]

Makes a clone of the Cc<T>.

When you clone an Cc<T>, it will create another pointer to the data and increase the strong reference counter.

Examples

use bacon_rajan_cc::Cc;

let five = Cc::new(5);

five.clone();

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<T: Ord + Trace> Ord for Cc<T>[src]

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

Comparison for two Cc<T>s.

The two are compared by calling cmp() on their inner values.

Examples

use bacon_rajan_cc::Cc;

let five = Cc::new(5);

five.partial_cmp(&Cc::new(5));

fn max(self, other: Self) -> Self1.21.0[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self1.21.0[src]

Compares and returns the minimum of two values. Read more

fn clamp(self, min: Self, max: Self) -> Self[src]

🔬 This is a nightly-only experimental API. (clamp)

Restrict a value to a certain interval. Read more

impl<T: Default + Trace> Default for Cc<T>[src]

fn default() -> Cc<T>[src]

Creates a new Cc<T>, with the Default value for T.

Examples

use bacon_rajan_cc::Cc;

let x: Cc<i32> = Default::default();

impl<T: PartialOrd + Trace> PartialOrd<Cc<T>> for Cc<T>[src]

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

Partial comparison for two Cc<T>s.

The two are compared by calling partial_cmp() on their inner values.

Examples

use bacon_rajan_cc::Cc;

let five = Cc::new(5);

five.partial_cmp(&Cc::new(5));

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

Less-than comparison for two Cc<T>s.

The two are compared by calling < on their inner values.

Examples

use bacon_rajan_cc::Cc;

let five = Cc::new(5);

five < Cc::new(5);

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

'Less-than or equal to' comparison for two Cc<T>s.

The two are compared by calling <= on their inner values.

Examples

use bacon_rajan_cc::Cc;

let five = Cc::new(5);

five <= Cc::new(5);

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

Greater-than comparison for two Cc<T>s.

The two are compared by calling > on their inner values.

Examples

use bacon_rajan_cc::Cc;

let five = Cc::new(5);

five > Cc::new(5);

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

'Greater-than or equal to' comparison for two Cc<T>s.

The two are compared by calling >= on their inner values.

Examples

use bacon_rajan_cc::Cc;

let five = Cc::new(5);

five >= Cc::new(5);

impl<T: PartialEq + Trace> PartialEq<Cc<T>> for Cc<T>[src]

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

Equality for two Cc<T>s.

Two Cc<T>s are equal if their inner value are equal.

Examples

use bacon_rajan_cc::Cc;

let five = Cc::new(5);

five == Cc::new(5);

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

Inequality for two Cc<T>s.

Two Cc<T>s are unequal if their inner value are unequal.

Examples

use bacon_rajan_cc::Cc;

let five = Cc::new(5);

five != Cc::new(5);

impl<T: Trace> Drop for Cc<T>[src]

fn drop(&mut self)[src]

Drops the Cc<T>.

This will decrement the strong reference count. If the strong reference count becomes zero and the only other references are Weak<T> ones, drops the inner value.

Examples

use bacon_rajan_cc::Cc;

{
    let five = Cc::new(5);

    // stuff

    drop(five); // explicit drop
}
{
    let five = Cc::new(5);

    // stuff

} // implicit drop

impl<T: Eq + Trace> Eq for Cc<T>[src]

impl<T: Display + Trace> Display for Cc<T>[src]

impl<T: Debug + Trace> Debug for Cc<T>[src]

impl<T: Trace> Deref for Cc<T>[src]

type Target = T

The resulting type after dereferencing.

impl<T: Hash + Trace> Hash for Cc<T>[src]

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

Feeds a slice of this type into the given [Hasher]. Read more

impl<T: Trace> Pointer for Cc<T>[src]

Auto Trait Implementations

impl<T> !Sync for Cc<T>

impl<T> !Send for Cc<T>

impl<T> Unpin for Cc<T> where
    T: Unpin

impl<T> !RefUnwindSafe for Cc<T>

impl<T> !UnwindSafe for Cc<T>

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]