Skip to main content

CompactArc

Struct CompactArc 

Source
pub struct CompactArc<T: ?Sized + CompactArcDrop> { /* private fields */ }
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 Sizes

TypeSize
CompactArc<i64>8 bytes
CompactArc<str>8 bytes (thin!)
CompactArc<[T]>8 bytes (thin!)

Implementations§

Source§

impl<T: ?Sized + CompactArcDrop> CompactArc<T>

Source

pub fn ptr_eq(this: &Self, other: &Self) -> bool

Returns true if the two CompactArcs point to the same allocation.

Source

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

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.

Source

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

Returns the metadata stored in the header (used for count).

Source§

impl<T: CompactArcDrop> CompactArc<T>

Source

pub fn new(data: T) -> Self

Creates a new CompactArc<T> containing the given value.

Source

pub fn new_with_meta(data: T, meta: usize) -> Self

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.

Source

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

Attempts to unwrap the CompactArc, returning the inner value if this is the only reference.

Source

pub fn get_mut(this: &mut Self) -> Option<&mut T>

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.

Source

pub fn make_mut(this: &mut Self) -> &mut T
where T: Clone,

Makes a mutable reference to the inner value (clone-on-write).

If there are other references, clones the data into a new allocation.

Source

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

Returns a raw pointer to the contained data.

Source

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

Converts a CompactArc<T> into a raw pointer.

Source

pub unsafe fn from_raw(ptr: *const T) -> Self

Constructs a CompactArc<T> from a raw pointer.

§Safety

The raw pointer must have been previously returned by CompactArc::into_raw.

Source§

impl CompactArc<str>

Source

pub fn from_str_slice(s: &str) -> Self

Creates a new CompactArc<str> from a string slice.

The pointer is only 8 bytes (thin), with length stored in heap header.

Source

pub fn len(&self) -> usize

Returns the length of the string in bytes.

Source

pub fn is_empty(&self) -> bool

Returns true if the string is empty.

Source§

impl<T> CompactArc<[T]>

Source

pub fn from_vec(vec: Vec<T>) -> Self

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.

Source

pub fn from_compact_vec(vec: CompactVec<T>) -> Self

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.

Source§

impl<T: Clone> CompactArc<[T]>

Source

pub fn from_slice(slice: &[T]) -> Self

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.

Source§

impl<T> CompactArc<[T]>

Source

pub fn len(&self) -> usize

Returns the number of elements in the slice.

Source

pub fn is_empty(&self) -> bool

Returns true if the slice is empty.

Trait Implementations§

Source§

impl<T: CompactArcDrop> AsRef<T> for CompactArc<T>

Source§

fn as_ref(&self) -> &T

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

impl<T> AsRef<[T]> for CompactArc<[T]>

Source§

fn as_ref(&self) -> &[T]

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

impl AsRef<str> for CompactArc<str>

Source§

fn as_ref(&self) -> &str

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

impl<T: CompactArcDrop> Borrow<T> for CompactArc<T>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> Borrow<[T]> for CompactArc<[T]>

Source§

fn borrow(&self) -> &[T]

Immutably borrows from an owned value. Read more
Source§

impl Borrow<str> for CompactArc<str>

Source§

fn borrow(&self) -> &str

Immutably borrows from an owned value. Read more
Source§

impl<T: ?Sized + CompactArcDrop> Clone for CompactArc<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: CompactArcDrop + Debug> Debug for CompactArc<T>

Source§

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

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

impl Debug for CompactArc<str>

Source§

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

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

impl<T: Debug> Debug for CompactArc<[T]>

Source§

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

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

impl<T: CompactArcDrop + Default> Default for CompactArc<T>

Source§

fn default() -> Self

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

impl<T: CompactArcDrop> Deref for CompactArc<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl Deref for CompactArc<str>

Source§

type Target = str

The resulting type after dereferencing.
Source§

fn deref(&self) -> &str

Dereferences the value.
Source§

impl<T> Deref for CompactArc<[T]>

Source§

type Target = [T]

The resulting type after dereferencing.
Source§

fn deref(&self) -> &[T]

Dereferences the value.
Source§

impl<T: CompactArcDrop + Display> Display for CompactArc<T>

Source§

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

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

impl Display for CompactArc<str>

Source§

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

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

impl<T: ?Sized + CompactArcDrop> Drop for CompactArc<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬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
Source§

impl<T: CompactArcDrop + Eq> Eq for CompactArc<T>

Source§

impl Eq for CompactArc<str>

Source§

impl<T: Eq> Eq for CompactArc<[T]>

Source§

impl<T: Clone> From<&[T]> for CompactArc<[T]>

Source§

fn from(slice: &[T]) -> Self

Converts to this type from the input type.
Source§

impl From<&str> for CompactArc<str>

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl From<CompactArc<[Value]>> for Row

Source§

fn from(values: CompactArc<[Value]>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for CompactArc<str>

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl<T: CompactArcDrop> From<T> for CompactArc<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for CompactArc<[T]>

Source§

fn from(vec: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: CompactArcDrop + Hash> Hash for CompactArc<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Hash for CompactArc<str>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: Hash> Hash for CompactArc<[T]>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: CompactArcDrop + Ord> Ord for CompactArc<T>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl Ord for CompactArc<str>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<T: Ord> Ord for CompactArc<[T]>

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<T: CompactArcDrop + PartialEq> PartialEq for CompactArc<T>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialEq for CompactArc<str>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq> PartialEq for CompactArc<[T]>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: CompactArcDrop + PartialOrd> PartialOrd for CompactArc<T>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PartialOrd for CompactArc<str>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: PartialOrd> PartialOrd for CompactArc<[T]>

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T: ?Sized + CompactArcDrop + Send + Sync> Send for CompactArc<T>

Source§

impl<T: ?Sized + CompactArcDrop + Send + Sync> Sync for CompactArc<T>

Auto Trait Implementations§

§

impl<T> Freeze for CompactArc<T>
where PhantomData<T>: Freeze, T: ?Sized,

§

impl<T> RefUnwindSafe for CompactArc<T>

§

impl<T> Unpin for CompactArc<T>
where PhantomData<T>: Unpin, T: ?Sized,

§

impl<T> UnsafeUnpin for CompactArc<T>
where PhantomData<T>: UnsafeUnpin, T: ?Sized,

§

impl<T> UnwindSafe for CompactArc<T>
where PhantomData<T>: UnwindSafe, T: ?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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> CompactArcDrop for T

Source§

unsafe fn drop_and_dealloc(ptr: *mut u8)

Drop the contained data and deallocate the header+data allocation. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V