[][src]Struct triomphe::UniqueArc

pub struct UniqueArc<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.

UniqueArc 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 = UniqueArc::new(data);
x[4] = 7; // mutate!
let y = x.shareable(); // y is an Arc<T>

Methods

impl<T> UniqueArc<T>[src]

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

Construct a new UniqueArc

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

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

Trait Implementations

impl<T> Deref for UniqueArc<T>[src]

type Target = T

The resulting type after dereferencing.

impl<T> DerefMut for UniqueArc<T>[src]

Auto Trait Implementations

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

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

Blanket Implementations

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

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

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.

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

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

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