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>
impl<T: RcObject> Rc<T>
Sourcepub fn new_many<const N: usize>(obj: T) -> [Self; N]
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.
Sourcepub fn new_many_iter(obj: T, count: usize) -> NewRcIter<T> ⓘ
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.
Sourcepub fn weak_many<const N: usize>(&self) -> [Weak<T>; N]
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.
Sourcepub fn with_tag(self, tag: usize) -> Self
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.
Sourcepub fn finalize(self, guard: &Guard)
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.
Sourcepub fn downgrade(&self) -> Weak<T>
pub fn downgrade(&self) -> Weak<T>
Creates a Weak pointer by incrementing the weak reference counter.
Sourcepub fn snapshot<'g>(&self, guard: &'g Guard) -> Snapshot<'g, T>
pub fn snapshot<'g>(&self, guard: &'g Guard) -> Snapshot<'g, T>
Creates a Snapshot pointer to the same object.
Sourcepub unsafe fn deref(&self) -> &T
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.
Sourcepub unsafe fn deref_mut(&mut self) -> &mut T
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.
Sourcepub fn as_ref(&self) -> Option<&T>
pub fn as_ref(&self) -> Option<&T>
Dereferences the pointer and returns an immutable reference if it is not null.