pub struct Arc<T: ?Sized> { /* private fields */ }Expand description
Mock implementation of std::sync::Arc.
Implementations§
Source§impl<T: ?Sized> Arc<T>
impl<T: ?Sized> Arc<T>
Sourcepub fn from_std(std: Arc<T>) -> Self
pub fn from_std(std: Arc<T>) -> Self
Converts std::sync::Arc to loom::sync::Arc.
This is needed to create a loom::sync::Arc<T> where T: !Sized.
§Panics
If the provided Arc has copies (i.e., if it is not unique).
§Examples
While std::sync::Arc with T: !Sized can be created by coercing an
std::sync::Arc with a sized value:
let sized: std::sync::Arc<[u8; 3]> = std::sync::Arc::new([1, 2, 3]);
let _unsized: std::sync::Arc<[u8]> = sized; // coercionloom::sync::Arc can’t be created in the same way:
use loom::sync::Arc;
let sized: Arc<[u8; 3]> = Arc::new([1, 2, 3]);
let _unsized: Arc<[u8]> = sized; // error: mismatched typesThis is because std::sync::Arc uses an unstable trait called CoerceUnsized
that loom can’t use. To create loom::sync::Arc with an unsized inner value
first create a std::sync::Arc of an appropriate type and then use this method:
use loom::sync::Arc;
let std: std::sync::Arc<[u8]> = std::sync::Arc::new([1, 2, 3]);
let loom: Arc<[u8]> = Arc::from_std(std);
let std: std::sync::Arc<dyn Send + Sync> = std::sync::Arc::new([1, 2, 3]);
let loom: Arc<dyn Send + Sync> = Arc::from_std(std);Sourcepub fn strong_count(this: &Self) -> usize
pub fn strong_count(this: &Self) -> usize
Gets the number of strong (Arc) pointers to this value.
Sourcepub unsafe fn increment_strong_count(ptr: *const T)
pub unsafe fn increment_strong_count(ptr: *const T)
Increments the strong reference count on the Arc<T> associated with the
provided pointer by one.
§Safety
The pointer must have been obtained through Arc::into_raw, and the
associated Arc instance must be valid (i.e. the strong count must be at
least 1) for the duration of this method.
Sourcepub unsafe fn decrement_strong_count(ptr: *const T)
pub unsafe fn decrement_strong_count(ptr: *const T)
Decrements the strong reference count on the Arc<T> associated with the
provided pointer by one.
§Safety
The pointer must have been obtained through Arc::into_raw, and the
associated Arc instance must be valid (i.e. the strong count must be at
least 1) when invoking this method. This method can be used to release the final
Arc and backing storage, but should not be called after the final Arc has been
released.
Sourcepub fn get_mut(this: &mut Self) -> Option<&mut T>
pub fn get_mut(this: &mut Self) -> Option<&mut T>
Returns a mutable reference to the inner value, if there are
no other Arc pointers to the same value.
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 value (not
just values that compare as equal).
Sourcepub unsafe fn from_raw(ptr: *const T) -> Self
pub unsafe fn from_raw(ptr: *const T) -> Self
Constructs an Arc from a raw pointer.
§Safety
The raw pointer must have been previously returned by a call to
Arc<U>::into_raw where U must have the same size and
alignment as T. This is trivially true if U is T.
Note that if U is not T but has the same size and alignment, this is
basically like transmuting references of different types. See
mem::transmute for more information on what
restrictions apply in this case.
The user of from_raw has to make sure a specific value of T is only
dropped once.
This function is unsafe because improper use may lead to memory unsafety,
even if the returned Arc<T> is never accessed.