Struct loom::sync::Arc

source ·
pub struct Arc<T: ?Sized> { /* private fields */ }
Expand description

Mock implementation of std::sync::Arc.

Implementations§

source§

impl<T> Arc<T>

source

pub fn new(value: T) -> Arc<T>

Constructs a new Arc<T>.

source

pub fn pin(data: T) -> Pin<Arc<T>>

Constructs a new Pin<Arc<T>>.

source

pub fn try_unwrap(this: Arc<T>) -> Result<T, Arc<T>>

Returns the inner value, if the Arc has exactly one strong reference.

source§

impl<T: ?Sized> Arc<T>

source

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; // coercion

loom::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 types

This 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);
source

pub fn strong_count(this: &Self) -> usize

Gets the number of strong (Arc) pointers to this value.

source

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.

source

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.

source

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.

source

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).

source

pub fn into_raw(this: Self) -> *const T

Consumes the Arc, returning the wrapped pointer.

source

pub fn as_ptr(this: &Self) -> *const T

Provides a raw pointer to the data.

source

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.

Trait Implementations§

source§

impl<T: ?Sized> AsRef<T> for Arc<T>

source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<T: ?Sized> Borrow<T> for Arc<T>

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T: ?Sized> Clone for Arc<T>

source§

fn clone(&self) -> Arc<T>

Returns a copy 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: Debug + ?Sized> Debug for Arc<T>

source§

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

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

impl<T: Default> Default for Arc<T>

source§

fn default() -> Arc<T>

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

impl<T: ?Sized> Deref for Arc<T>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

impl<T: ?Sized> Drop for Arc<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T> From<T> for Arc<T>

source§

fn from(t: T) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<T> Freeze for Arc<T>
where T: ?Sized,

§

impl<T> RefUnwindSafe for Arc<T>
where T: RefUnwindSafe + ?Sized,

§

impl<T> Send for Arc<T>
where T: Sync + Send + ?Sized,

§

impl<T> Sync for Arc<T>
where T: Sync + Send + ?Sized,

§

impl<T> Unpin for Arc<T>
where T: ?Sized,

§

impl<T> UnwindSafe for Arc<T>
where T: RefUnwindSafe + ?Sized,

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> From<!> for T

source§

fn from(t: !) -> T

Converts to this type from the input type.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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,

§

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>,

§

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>,

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more