Struct bacon_rajan_cc::Cc

source ·
pub struct Cc<T: 'static + Trace> { /* private fields */ }
Expand description

A reference-counted pointer type over an immutable value.

See the module level documentation for more details.

Implementations§

Constructs a new Cc<T>.

Examples
use bacon_rajan_cc::Cc;

let five = Cc::new(5);

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

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

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

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

Get the number of strong references to this value.

Get the number of weak references to this value.

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§

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();
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

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

Examples
use bacon_rajan_cc::Cc;

let x: Cc<i32> = Default::default();
The resulting type after dereferencing.
Dereferences the value.
Formats the value using the given formatter. Read more

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
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more

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));
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more

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

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

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

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

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

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

‘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);
Formats the value using the given formatter.
Invoke the Tracer on each of the CcBoxPtrs owned by this Trace instance. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.