Struct rc::Rc [] [src]

pub struct Rc<T> { /* fields omitted */ }

A reference-counted pointer type over an immutable value.

See the module level documentation for more details.

Methods

impl<T> Rc<T>
[src]

Constructs a new Rc<T>.

Examples

use rc::Rc;

let five = Rc::new(5);

Unwraps the contained value if the Rc<T> is unique.

If the Rc<T> is not unique, an Err is returned with the same Rc<T>.

Examples

use rc::Rc;

let x = Rc::new(3);
assert_eq!(Rc::try_unwrap(x), Ok(3));

let x = Rc::new(4);
let _y = x.clone();
assert_eq!(Rc::try_unwrap(x), Err(Rc::new(4)));

impl<T> Rc<T>
[src]

Downgrades the Rc<T> to a Weak<T> reference.

Examples

use rc::Rc;

let five = Rc::new(5);

let weak_five = five.downgrade();

Get the number of weak references to this value.

Get the number of strong references to this value.

Returns true if there are no other Rc or Weak<T> values that share the same inner value.

Examples

use rc::Rc;

let five = Rc::new(5);

assert!(Rc::is_unique(&five));

Returns a mutable reference to the contained value if the Rc<T> is unique.

Returns None if the Rc<T> is not unique.

Examples

use rc::Rc;

let mut x = Rc::new(3);
*Rc::get_mut(&mut x).unwrap() = 4;
assert_eq!(*x, 4);

let _y = x.clone();
assert!(Rc::get_mut(&mut x).is_none());

impl<T: Clone> Rc<T>
[src]

Make a mutable reference from the given Rc<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 rc::Rc;

let mut five = Rc::new(5);

let mut_five = five.make_unique();

Trait Implementations

impl<T> Deref for Rc<T>
[src]

The resulting type after dereferencing

The method called to dereference a value

impl<T> Drop for Rc<T>
[src]

Drops the Rc<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 rc::Rc;

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

    // stuff

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

    // stuff

} // implicit drop

impl<T> Clone for Rc<T>
[src]

Makes a clone of the Rc<T>.

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

Examples

use rc::Rc;

let five = Rc::new(5);

five.clone();

Performs copy-assignment from source. Read more

impl<T: Default> Default for Rc<T>
[src]

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

Examples

use rc::Rc;

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

impl<T: PartialEq> PartialEq for Rc<T>
[src]

Equality for two Rc<T>s.

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

Examples

use rc::Rc;

let five = Rc::new(5);

five == Rc::new(5);

Inequality for two Rc<T>s.

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

Examples

use rc::Rc;

let five = Rc::new(5);

five != Rc::new(5);

impl<T: Eq> Eq for Rc<T>
[src]

impl<T: PartialOrd> PartialOrd for Rc<T>
[src]

Partial comparison for two Rc<T>s.

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

Examples

use rc::Rc;

let five = Rc::new(5);

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

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

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

Examples

use rc::Rc;

let five = Rc::new(5);

five < Rc::new(5);

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

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

Examples

use rc::Rc;

let five = Rc::new(5);

five <= Rc::new(5);

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

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

Examples

use rc::Rc;

let five = Rc::new(5);

five > Rc::new(5);

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

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

Examples

use rc::Rc;

let five = Rc::new(5);

five >= Rc::new(5);

impl<T: Ord> Ord for Rc<T>
[src]

Comparison for two Rc<T>s.

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

Examples

use rc::Rc;

let five = Rc::new(5);

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

impl<T: Hash> Hash for Rc<T>
[src]

Feeds this value into the given [Hasher]. Read more

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

impl<T: Display> Display for Rc<T>
[src]

Formats the value using the given formatter. Read more

impl<T: Debug> Debug for Rc<T>
[src]

Formats the value using the given formatter.

impl<T> Pointer for Rc<T>
[src]

Formats the value using the given formatter.