ArcBox

Struct ArcBox 

Source
pub struct ArcBox<T: ?Sized>(/* private fields */);
Expand description

An Arc that is known to be uniquely owned

When Arcs are constructed, they are known to be uniquely owned. In such a case it is safe to mutate the contents of the Arc. Normally, one would just handle this by mutating the data on the stack before allocating the Arc, however it’s possible the data is large or unsized and you need to heap-allocate it earlier in such a way that it can be freely converted into a regular Arc once you’re done.

ArcBox exists for this purpose, when constructed it performs the same allocations necessary for an Arc, however it allows mutable access. Once the mutation is finished, you can call .shareable() and get a regular Arc out of it.

let data = [1, 2, 3, 4, 5];
let mut x = ArcBox::new(data);
x[4] = 7; // mutate!
let y = x.shareable(); // y is an Arc<T>

Implementations§

Source§

impl<T> ArcBox<T>

Source

pub fn new(data: T) -> Self

Construct a new ArcBox

Source

pub fn new_uninit() -> ArcBox<MaybeUninit<T>>

Construct an uninitialized ArcBox

Source

pub fn into_inner(this: Self) -> T

Gets the inner value of this ArcBox

Source

pub fn shareable_ref(self) -> ArcRef<'static, T>

Convert to a shareable ArcRef<'static, T> once we’re done mutating it

Source§

impl<T: ?Sized> ArcBox<T>

Source

pub fn shareable(self) -> Arc<T>

Convert to a shareable Arc<T> once we’re done mutating it

Source§

impl<T> ArcBox<MaybeUninit<T>>

Source

pub unsafe fn assume_init(this: Self) -> ArcBox<T>

Convert to an initialized Arc.

§Safety

This function is equivalent to MaybeUninit::assume_init and has the same safety requirements. You are responsible for ensuring that the T has actually been initialized before calling this method.

Trait Implementations§

Source§

impl<S: ?Sized + SliceDst> AllocSliceDst<S> for ArcBox<S>

This implementation is based on that in the documentation for slice-dst.

§Safety

This function merely calls try_new_slice with an initializer statically guaranteed never to fail, and therefore is safe if and only if try_new_slice is.

Source§

unsafe fn new_slice_dst<I>(len: usize, init: I) -> Self
where I: FnOnce(NonNull<S>),

Create a new custom slice DST. Read more
Source§

impl<T: ?Sized> AsMut<T> for ArcBox<T>

Source§

fn as_mut(&mut self) -> &mut T

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

impl<T: ?Sized> AsRef<T> for ArcBox<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 ArcBox<T>

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T: ?Sized> BorrowMut<T> for ArcBox<T>

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T: Clone> Clone for ArcBox<T>

Source§

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

Returns a duplicate 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, U: ?Sized> CoerciblePtr<U> for ArcBox<T>

§Safety

This leverages the correctness of Arc’s CoerciblePtr impl. Additionally, we must ensure that this can not be used to violate the safety invariants of ArcBox, which require that we can not duplicate the Arc, such that replace_ptr returns a valid instance. This holds since it consumes a unique owner of the contained ArcInner.

Source§

type Pointee = T

The type we point to. This influences which kinds of unsizing are possible.
Source§

type Output = ArcBox<U>

The output type when unsizing the pointee to U.
Source§

fn as_sized_ptr(&mut self) -> *mut T

Get the raw inner pointer.
Source§

unsafe fn replace_ptr(self, new: *mut U) -> ArcBox<U>

Replace the container inner pointer with an unsized version. Read more
Source§

impl<T: Debug> Debug for ArcBox<T>

Source§

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

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

impl<T: Default> Default for ArcBox<T>

Source§

fn default() -> ArcBox<T>

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

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

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.
Source§

impl<T: ?Sized> DerefMut for ArcBox<T>

Source§

fn deref_mut(&mut self) -> &mut T

Mutably dereferences the value.
Source§

impl<T: Display> Display for ArcBox<T>

Source§

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

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

impl<S: ?Sized + SliceDst> TryAllocSliceDst<S> for ArcBox<S>

§Safety

Source§

unsafe fn try_new_slice_dst<I, E>(len: usize, init: I) -> Result<Self, E>
where I: FnOnce(NonNull<S>) -> Result<(), E>,

Create a new custom slice DST with a fallible initialization function. Read more
Source§

impl<T: ?Sized> TryFrom<Arc<T>> for ArcBox<T>

Source§

type Error = Arc<T>

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

fn try_from(arc: Arc<T>) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<T> Unpin for ArcBox<T>
where T: Unpin + ?Sized,

§

impl<T> UnwindSafe for ArcBox<T>

Blanket Implementations§

Source§

impl<T, A, P> Access<T> for P
where A: Access<T> + ?Sized, P: Deref<Target = A>,

Source§

type Guard = <A as Access<T>>::Guard

A guard object containing the value and keeping it alive. Read more
Source§

fn load(&self) -> <P as Access<T>>::Guard

The loading method. Read more
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, U> CoerceUnsize<U> for T
where T: CoerciblePtr<U>, U: ?Sized,

Source§

fn unsize<F>(self, with: Coercion<Self::Pointee, U, F>) -> Self::Output
where F: FnOnce(*const Self::Pointee) -> *const U,

Convert a pointer, as if with unsize coercion. Read more
Source§

impl<T, A> DynAccess<T> for A
where A: Access<T>, <A as Access<T>>::Guard: 'static,

Source§

fn load(&self) -> DynGuard<T>

The equivalent of Access::load.
Source§

impl<T> Erasable for T

Source§

const ACK_1_1_0: bool = true

Whether this implementor has acknowledged the 1.1.0 update to unerase’s documented implementation requirements. Read more
Source§

unsafe fn unerase(this: NonNull<Erased>) -> NonNull<T>

Unerase this erased pointer. Read more
Source§

fn erase(this: NonNull<Self>) -> NonNull<Erased>

Turn this erasable pointer into an erased pointer. 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> 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 = 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>,

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.