Struct CompactArc Copy item path Source pub struct CompactArc<T: ?Sized + CompactArcDrop > { }Expand description A thread-safe reference-counted pointer without weak reference support.
CompactArc<T> provides shared ownership of a value of type T, allocated
on the heap. It saves memory compared to std::sync::Arc:
8 bytes less per allocation (no weak count)
Thin pointers for DSTs (8 bytes instead of 16 for str and [T])
§ Pointer SizesType Size
CompactArc<i64>8 bytes
CompactArc<str>8 bytes (thin!)
CompactArc<[T]>8 bytes (thin!)
Returns true if the two CompactArcs point to the same allocation.
Returns the number of strong references to this allocation.
Note: This uses Relaxed ordering and should only be used for
debugging/logging purposes, not for synchronization decisions.
Returns the metadata stored in the header (used for count).
Creates a new CompactArc<T> containing the given value.
Creates a new CompactArc<T> containing the given value and metadata.
The metadata is stored in the header’s len field, which is unused for Sized types.
Attempts to unwrap the CompactArc, returning the inner value if this
is the only reference.
Gets a mutable reference to the inner value, if there are no other references.
Uses Acquire ordering to synchronize with other threads that may have
dropped their references, ensuring all their modifications are visible.
Makes a mutable reference to the inner value (clone-on-write).
If there are other references, clones the data into a new allocation.
Returns a raw pointer to the contained data.
Converts a CompactArc<T> into a raw pointer.
Constructs a CompactArc<T> from a raw pointer.
§ Safety
The raw pointer must have been previously returned by CompactArc::into_raw.
Creates a new CompactArc<str> from a string slice.
The pointer is only 8 bytes (thin), with length stored in heap header.
Returns the length of the string in bytes.
Returns true if the string is empty.
Creates a new CompactArc<[T]> by moving elements from a Vec.
This is more efficient than from_slice as it moves elements instead of cloning.
Creates a new CompactArc<[T]> by moving elements from a CompactVec.
This is more efficient than from_slice as it moves elements instead of cloning.
Avoids the intermediate Vec conversion compared to from_vec.
Creates a new CompactArc<[T]> from a slice by cloning elements.
The pointer is only 8 bytes (thin), with length stored in heap header.
§ Panic Safety
If T::clone() panics, all successfully cloned elements are dropped
and the allocation is freed. No memory is leaked.
Returns the number of elements in the slice.
Returns true if the slice is empty.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Immutably borrows from an owned value.
Read more Immutably borrows from an owned value.
Read more Immutably borrows from an owned value.
Read more Performs copy-assignment from
source.
Read more Formats the value using the given formatter.
Read more Formats the value using the given formatter.
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.
The resulting type after dereferencing.
Dereferences the value.
The resulting type after dereferencing.
Dereferences the value.
Formats the value using the given formatter.
Read more Formats the value using the given formatter.
Read more Executes the destructor for this type.
Read more 🔬 This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to
Drop::drop, it requires
self
to be pinned.
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.
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 is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range.
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 is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range.
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 is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range.
Read more This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more This method returns an ordering between
self and
other values if one exists.
Read more Tests less than (for
self and
other) and is used by the
< operator.
Read more Tests less than or equal to (for
self and
other) and is used by the
<= operator.
Read more Tests greater than (for
self and
other) and is used by the
>
operator.
Read more Tests greater than or equal to (for
self and
other) and is used by
the
>= operator.
Read more Immutably borrows from an owned value.
Read more Mutably borrows from an owned value.
Read more 🔬 This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from
self to
dest.
Read more Drop the contained data and deallocate the header+data allocation.
Read more Returns the argument unchanged.
Calls U::from(self).
That is, this conversion is whatever the implementation of
From <T> for U chooses to do.
🔬 This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.