Rc

Struct Rc 

Source
pub struct Rc<T: RcObject> { /* private fields */ }
Expand description

A reference-counted pointer to an object of type T.

When T implements Send and Sync, Rc<T> also implements these traits.

The pointer must be properly aligned. Since it is aligned, a tag can be stored into the unused least significant bits of the address. For example, the tag for a pointer to a sized type T should be less than (1 << align_of::<T>().trailing_zeros()).

Implementations§

Source§

impl<T: RcObject> Rc<T>

Source

pub fn null() -> Self

Constructs a null Rc pointer.

Source

pub fn is_null(&self) -> bool

Returns true if the pointer is null ignoring the tag.

Source

pub fn new(obj: T) -> Self

Constructs a new Rc by allocating a new reference-couned object.

Source

pub fn new_many<const N: usize>(obj: T) -> [Self; N]

Constructs multiple Rcs that point to the same object, which is allocated as a new reference-counted object.

This method is more efficient than calling Rc::new once and cloning multiple times because it is sufficient to set the reference counter only once, avoiding expensive read-modify-write operations.

Source

pub fn new_many_iter(obj: T, count: usize) -> NewRcIter<T>

Constructs an iterator that produces the Rcs that point to the same object, which is allocated as a new reference-counted object.

This method is more efficient than calling Rc::new once and cloning multiple times because it is sufficient to set the reference counter only once, avoiding expensive read-modify-write operations.

Source

pub fn weak_many<const N: usize>(&self) -> [Weak<T>; N]

Constructs multiple Weaks that point to the current object.

This method is more efficient than calling Rc::downgrade multiple times because it is sufficient to set the reference counter only once, avoiding expensive read-modify-write operations.

Source

pub fn tag(&self) -> usize

Returns the tag stored within the pointer.

Source

pub fn with_tag(self, tag: usize) -> Self

Returns the same pointer, but tagged with tag. tag is truncated to be fit into the unused bits of the pointer to T.

Source

pub fn finalize(self, guard: &Guard)

Consumes this pointer and release a strong reference count it was owning.

This method is more efficient than just Droping the pointer. The Drop method checks whether the current thread is pinned and pin the thread if it is not. However, this method skips that procedure as it already requires Guard as an argument.

Source

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

Creates a Weak pointer by incrementing the weak reference counter.

Source

pub fn snapshot<'g>(&self, guard: &'g Guard) -> Snapshot<'g, T>

Creates a Snapshot pointer to the same object.

Source

pub unsafe fn deref(&self) -> &T

Dereferences the pointer and returns an immutable reference.

It does not check whether the pointer is null.

§Safety

The pointer must be a valid memory location to dereference.

Source

pub unsafe fn deref_mut(&mut self) -> &mut T

Dereferences the pointer and returns a mutable reference.

It does not check whether the pointer is null.

§Safety

The pointer must be a valid memory location to dereference and other threads must not have references to the object.

Source

pub fn as_ref(&self) -> Option<&T>

Dereferences the pointer and returns an immutable reference if it is not null.

Source

pub unsafe fn as_mut(&mut self) -> Option<&mut T>

Dereferences the pointer and returns a mutable reference if it is not null.

§Safety

Other threads must not have references to the object.

Source

pub fn ptr_eq(&self, other: &Self) -> bool

Returns true if the two pointer values, including the tag values set by with_tag, are identical.

Trait Implementations§

Source§

impl<T: RcObject> Clone for Rc<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: RcObject + Debug> Debug for Rc<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: RcObject> Default for Rc<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: RcObject> Drop for Rc<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: RcObject> From<&Rc<T>> for AtomicRc<T>

Source§

fn from(value: &Rc<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: RcObject> From<&Rc<T>> for AtomicWeak<T>

Source§

fn from(value: &Rc<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: RcObject> From<Rc<T>> for AtomicRc<T>

Source§

fn from(value: Rc<T>) -> Self

Converts to this type from the input type.
Source§

impl<'g, T: RcObject> From<Snapshot<'g, T>> for Rc<T>

Source§

fn from(value: Snapshot<'g, T>) -> Self

Converts to this type from the input type.
Source§

impl<T: RcObject + Hash> Hash for Rc<T>

Source§

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

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

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

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: RcObject + Ord> Ord for Rc<T>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<T: RcObject + PartialEq> PartialEq for Rc<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: RcObject + PartialOrd> PartialOrd for Rc<T>

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: RcObject> Pointer for Rc<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: RcObject + Eq> Eq for Rc<T>

Source§

impl<T: RcObject + Send + Sync> Send for Rc<T>

Source§

impl<T: RcObject + Send + Sync> Sync for Rc<T>

Auto Trait Implementations§

§

impl<T> Freeze for Rc<T>

§

impl<T> RefUnwindSafe for Rc<T>
where T: RefUnwindSafe,

§

impl<T> Unpin for Rc<T>
where T: Unpin,

§

impl<T> UnwindSafe for Rc<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.