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]
fn new(value: T) -> Rc<T>
fn try_unwrap(rc: Rc<T>) -> Result<T, Rc<T>>
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]
fn downgrade(&self) -> Weak<T>
Downgrades the Rc<T>
to a Weak<T>
reference.
Examples
use rc::Rc; let five = Rc::new(5); let weak_five = five.downgrade();
fn weak_count(this: &Rc<T>) -> usize
Get the number of weak references to this value.
fn strong_count(this: &Rc<T>) -> usize
Get the number of strong references to this value.
fn is_unique(rc: &Rc<T>) -> bool
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));
fn get_mut(rc: &mut Rc<T>) -> Option<&mut T>
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]
fn make_unique(&mut self) -> &mut T
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]
type Target = T
The resulting type after dereferencing
fn deref(&self) -> &T
The method called to dereference a value
impl<T> Drop for Rc<T>
[src]
fn drop(&mut self)
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,
drop
s 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]
fn clone(&self) -> Rc<T>
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();
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl<T: Default> Default for Rc<T>
[src]
fn default() -> Rc<T>
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]
fn eq(&self, other: &Rc<T>) -> bool
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);
fn ne(&self, other: &Rc<T>) -> bool
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]
fn partial_cmp(&self, other: &Rc<T>) -> Option<Ordering>
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));
fn lt(&self, other: &Rc<T>) -> bool
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);
fn le(&self, other: &Rc<T>) -> bool
'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);
fn gt(&self, other: &Rc<T>) -> bool
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);
fn ge(&self, other: &Rc<T>) -> bool
'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]
fn cmp(&self, other: &Rc<T>) -> Ordering
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]
fn hash<H: Hasher>(&self, state: &mut H)
Feeds this value into the given [Hasher
]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more