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>
impl<T> ArcBox<T>
Sourcepub fn new_uninit() -> ArcBox<MaybeUninit<T>>
pub fn new_uninit() -> ArcBox<MaybeUninit<T>>
Construct an uninitialized ArcBox
Sourcepub fn into_inner(this: Self) -> T
pub fn into_inner(this: Self) -> T
Gets the inner value of this ArcBox
Convert to a shareable ArcRef<'static, T> once we’re done mutating it
Source§impl<T> ArcBox<MaybeUninit<T>>
impl<T> ArcBox<MaybeUninit<T>>
Sourcepub unsafe fn assume_init(this: Self) -> ArcBox<T>
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.
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§impl<T: ?Sized> BorrowMut<T> for ArcBox<T>
impl<T: ?Sized> BorrowMut<T> for ArcBox<T>
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
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.
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§fn as_sized_ptr(&mut self) -> *mut T
fn as_sized_ptr(&mut self) -> *mut T
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>
impl<T> Sync for ArcBox<T>
impl<T> Unpin for ArcBox<T>
impl<T> UnwindSafe for ArcBox<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T, U> CoerceUnsize<U> for Twhere
T: CoerciblePtr<U>,
U: ?Sized,
impl<T, U> CoerceUnsize<U> for Twhere
T: CoerciblePtr<U>,
U: ?Sized,
Source§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
Access::load.