[][src]Struct fragile::Fragile

pub struct Fragile<T> { /* fields omitted */ }

A Fragile<T> wraps a non sendable T to be safely send to other threads.

Once the value has been wrapped it can be sent to other threads but access to the value on those threads will fail.

If the value needs destruction and the fragile wrapper is on another thread the destructor will panic. Alternatively you can use Sticky<T> which is not going to panic but might temporarily leak the value.

Methods

impl<T> Fragile<T>[src]

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

Creates a new Fragile wrapping a value.

The value that is moved into the Fragile can be non Send and will be anchored to the thread that created the object. If the fragile wrapper type ends up being send from thread to thread only the original thread can interact with the value.

pub fn is_valid(&self) -> bool[src]

Returns true if the access is valid.

This will be false if the value was sent to another thread.

pub fn into_inner(self) -> T[src]

Consumes the Fragile, returning the wrapped value.

Panics

Panics if called from a different thread than the one where the original value was created.

pub fn try_into_inner(self) -> Result<T, Self>[src]

Consumes the Fragile, returning the wrapped value if successful.

The wrapped value is returned if this is called from the same thread as the one where the original value was created, otherwise the Fragile is returned as Err(self).

pub fn get(&self) -> &T[src]

Immutably borrows the wrapped value.

Panics

Panics if the calling thread is not the one that wrapped the value. For a non-panicking variant, use try_get.

pub fn get_mut(&mut self) -> &mut T[src]

Mutably borrows the wrapped value.

Panics

Panics if the calling thread is not the one that wrapped the value. For a non-panicking variant, use try_get_mut.

pub fn try_get(&self) -> Result<&T, InvalidThreadAccess>[src]

Tries to immutably borrow the wrapped value.

Returns None if the calling thread is not the one that wrapped the value.

pub fn try_get_mut(&mut self) -> Result<&mut T, InvalidThreadAccess>[src]

Tries to mutably borrow the wrapped value.

Returns None if the calling thread is not the one that wrapped the value.

Trait Implementations

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

impl<T: Debug> Debug for Fragile<T>[src]

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

impl<T: Display> Display for Fragile<T>[src]

impl<T> Drop for Fragile<T>[src]

impl<T: Eq> Eq for Fragile<T>[src]

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

impl<T: Ord> Ord for Fragile<T>[src]

impl<T: PartialEq> PartialEq<Fragile<T>> for Fragile<T>[src]

impl<T: PartialOrd> PartialOrd<Fragile<T>> for Fragile<T>[src]

impl<T> Send for Fragile<T>[src]

impl<T> Sync for Fragile<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Fragile<T> where
    T: RefUnwindSafe

impl<T> Unpin for Fragile<T>

impl<T> UnwindSafe for Fragile<T> where
    T: 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> From<!> 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> ToString for T where
    T: Display + ?Sized
[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.