pub struct Arc<T: ?Sized>(/* private fields */);Expand description
A thread-safe reference-counting pointer. ‘Arc’ stands for ‘Atomically Reference Counted’.
The type Arc<T> provides shared ownership cod
of a value of type T,
allocated in the heap. Invoking clone on Arc produces
a new Arc instance, which points to the same allocation on the heap as the
source Arc, while increasing a reference count. When the last Arc
pointer to a given allocation is destroyed, the value stored in that allocation (often
referred to as “inner value”) is also dropped.
Implementations§
Source§impl<T> Arc<T>
impl<T> Arc<T>
Sourcepub fn try_new(data: T) -> Result<Arc<T>, AllocError>
pub fn try_new(data: T) -> Result<Arc<T>, AllocError>
Constructs a new Arc<T>, returning an error if allocation fails.
Source§impl<T: ?Sized> Arc<T>
impl<T: ?Sized> Arc<T>
pub fn into_std(self) -> StdArc<T>
pub fn from_std(a: StdArc<T>) -> Self
Sourcepub fn weak_count(this: &Self) -> usize
pub fn weak_count(this: &Self) -> usize
Sourcepub fn strong_count(this: &Self) -> usize
pub fn strong_count(this: &Self) -> usize
Gets the number of strong (Arc) pointers to this allocation.
§Safety
This method by itself is safe, but using it correctly requires extra care. Another thread can change the strong count at any time, including potentially between calling this method and acting on the result.
Sourcepub fn ptr_eq(this: &Self, other: &Self) -> bool
pub fn ptr_eq(this: &Self, other: &Self) -> bool
Returns true if the two Arcs point to the same allocation
(in a vein similar to std::ptr::eq).