#[repr(transparent)]
pub struct Arc<T: ?Sized> { /* private fields */ }
Expand description

An atomically reference counted shared pointer

See the documentation for Arc in the standard library. Unlike the standard library Arc, this Arc does not support weak reference counting.

Implementations

Construct an Arc<T>

Reconstruct the Arc from a raw pointer obtained from into_raw()

Note: This raw pointer will be offset in the allocation and must be preceded by the atomic count.

It is recommended to use OffsetArc for this

Temporarily converts |self| into a bonafide OffsetArc and exposes it to the provided callback. The refcount is not modified.

Converts an Arc into a OffsetArc. This consumes the Arc, so the refcount is not modified.

Converts a OffsetArc into an Arc. This consumes the OffsetArc, so the refcount is not modified.

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

Otherwise, an Err is returned with the same Arc that was passed in.

Examples
use triomphe::Arc;

let x = Arc::new(3);
assert_eq!(Arc::try_unwrap(x), Ok(3));

let x = Arc::new(4);
let _y = Arc::clone(&x);
assert_eq!(*Arc::try_unwrap(x).unwrap_err(), 4);

Convert the Arc to a raw pointer, suitable for use across FFI

Note: This returns a pointer to the data T, which is offset in the allocation.

It is recommended to use OffsetArc for this.

Returns the raw pointer.

Same as into_raw except self isn’t consumed.

Produce a pointer to the data that can be converted back to an Arc. This is basically an &Arc<T>, without the extra indirection. It has the benefits of an &T but also knows about the underlying refcount and can be converted into more Arc<T>s if necessary.

Returns the address on the heap of the Arc itself – not the T within it – for memory reporting.

Test pointer equality between the two Arcs, i.e. they must be the same allocation

Create an Arc contains an MaybeUninit<T>.

👎Deprecated since 0.1.7:

this function previously was UB and now panics for non-unique Arcs. Use UniqueArc::write instead.

Calls MaybeUninit::write on the value contained.

Panics

If the Arc is not unique.

Obtain a mutable pointer to the stored MaybeUninit<T>.

Safety

Must initialize all fields before calling this function.

Create an Arc contains an array [MaybeUninit<T>] of len.

👎Deprecated since 0.1.8:

this function previously was UB and now panics for non-unique Arcs. Use UniqueArc or get_mut instead.

Obtain a mutable slice to the stored [MaybeUninit<T>].

Safety

Must initialize all fields before calling this function.

Makes a mutable reference to the Arc, cloning if necessary

This is functionally equivalent to Arc::make_mut from the standard library.

If this Arc is uniquely owned, make_mut() will provide a mutable reference to the contents. If not, make_mut() will create a new Arc with a copy of the contents, update this to point to it, and provide a mutable reference to its contents.

This is useful for implementing copy-on-write schemes where you wish to avoid copying things if your Arc is not shared.

Makes a UniqueArc from an Arc, cloning if necessary.

If this Arc is uniquely owned, make_unique() will provide a UniqueArc containing this. If not, make_unique() will create a new Arc with a copy of the contents, update this to point to it, and provide a UniqueArc to it.

This is useful for implementing copy-on-write schemes where you wish to avoid copying things if your Arc is not shared.

If we have the only reference to T then unwrap it. Otherwise, clone T and return the clone.

Assuming arc_t is of type Arc<T>, this function is functionally equivalent to (*arc_t).clone(), but will avoid cloning the inner value where possible.

Provides mutable access to the contents if the Arc is uniquely owned.

Provides unique access to the arc if the Arc is uniquely owned.

Whether or not the Arc is uniquely owned (is the refcount 1?).

Gets the number of Arc pointers to this allocation

Returns a UniqueArc if the Arc has exactly one strong reference.

Otherwise, an Err is returned with the same Arc that was passed in.

Examples
use triomphe::{Arc, UniqueArc};

let x = Arc::new(3);
assert_eq!(UniqueArc::into_inner(Arc::try_unique(x).unwrap()), 3);

let x = Arc::new(4);
let _y = Arc::clone(&x);
assert_eq!(
    *Arc::try_unique(x).map(UniqueArc::into_inner).unwrap_err(),
    4,
);

Creates an Arc for a HeaderSlice using the given header struct and iterator to generate the slice. The resulting Arc will be fat.

Creates an Arc for a HeaderSlice using the given header struct and iterator to generate the slice. The resulting Arc will be fat.

Creates an Arc for a HeaderSlice using the given header struct and vec to generate the slice. The resulting Arc will be fat.

Creates an Arc for a HeaderSlice using the given header struct and a str slice to generate the slice. The resulting Arc will be fat.

Converts an Arc into a ThinArc. This consumes the Arc, so the refcount is not modified.

Converts a ThinArc into an Arc. This consumes the ThinArc, so the refcount is not modified.

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.
Immutably borrows from an owned value. Read more
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.
Deserialize this value from the given Serde deserializer. Read more
Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Formats the value using the given formatter.
Serialize this value into the given Serde serializer. Read more
The type returned in the event of a conversion error.
Performs the conversion.

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.

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
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. 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.