Struct loom::sync::Arc

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

Mock implementation of std::sync::Arc.

Implementations

Constructs a new Arc<T>.

Constructs a new Pin<Arc<T>>.

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

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

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

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.

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.

Returns a mutable reference to the inner value, if there are no other Arc pointers to the same value.

Returns true if the two Arcs point to the same value (not just values that compare as equal).

Consumes the Arc, returning the wrapped pointer.

Provides a raw pointer to the data.

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

The resulting type after dereferencing.

Dereferences the value.

Executes the destructor for this type. Read more

Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts to this type from the input type.

Returns the argument unchanged.

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

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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