[][src]Struct elysees::ArcBox

#[repr(transparent)]pub struct ArcBox<T: ?Sized>(_);

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. You can also attempt to cast an Arc back into a ArcBox, which will succeed if the Arc is unique

let data = [1, 2, 3, 4, 5];
let mut x = ArcBox::new(data);
let x_ptr = x.deref() as *const _;

x[4] = 7; // mutate!

// The allocation has been modified, but not moved
assert_eq!(x.deref(), &[1, 2, 3, 4, 7]);
assert_eq!(x_ptr, x.deref() as *const _);

let y = x.shareable(); // y is an Arc<T>

// The allocation has not been modified or moved
assert_eq!(y.deref(), &[1, 2, 3, 4, 7]);
assert_eq!(x_ptr, y.deref() as *const _);

Implementations

impl<T> ArcBox<T>[src]

pub fn new(data: T) -> Self[src]

Construct a new ArcBox

impl<T: ?Sized> ArcBox<T>[src]

pub fn shareable(self) -> Arc<T>[src]

Convert to a shareable Arc once we're done mutating it

Trait Implementations

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

impl<T: ?Sized> AsMut<T> for ArcBox<T>[src]

impl<T: ?Sized> AsRef<*const T> for ArcBox<T>[src]

impl<T: ?Sized> AsRef<*mut T> for ArcBox<T>[src]

impl<T: ?Sized> AsRef<NonNull<T>> for ArcBox<T>[src]

impl<T: ?Sized> AsRef<T> for ArcBox<T>[src]

impl<T: ?Sized> Borrow<T> for ArcBox<T>[src]

impl<T: ?Sized> BorrowMut<T> for ArcBox<T>[src]

impl<T: Clone> Clone for ArcBox<T>[src]

impl<T: Debug + ?Sized> Debug for ArcBox<T>[src]

impl<T: Default> Default for ArcBox<T>[src]

impl<T: ?Sized> Deref for ArcBox<T>[src]

type Target = T

The resulting type after dereferencing.

impl<T: ?Sized> DerefMut for ArcBox<T>[src]

impl<T: Eq + ?Sized> Eq for ArcBox<T>[src]

impl<T: ?Sized + Erasable> ErasablePtr for ArcBox<T>[src]

impl<T: Hash + ?Sized> Hash for ArcBox<T>[src]

impl<T: Ord + ?Sized> Ord for ArcBox<T>[src]

impl<T: PartialEq + ?Sized> PartialEq<ArcBox<T>> for ArcBox<T>[src]

impl<T: PartialOrd + ?Sized> PartialOrd<ArcBox<T>> for ArcBox<T>[src]

impl<T: ?Sized> StableDeref for ArcBox<T>[src]

impl<T> Stowable for ArcBox<T>[src]

impl<T: ?Sized> StructuralEq for ArcBox<T>[src]

impl<T: ?Sized> StructuralPartialEq for ArcBox<T>[src]

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

impl<T: ?Sized> UnionAlign for ArcBox<T> where
    ArcBox<T>: ErasablePtr
[src]

Auto Trait Implementations

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

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

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

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

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

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Erasable for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.