[][src]Struct fragile::Sticky

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

A Sticky<T> keeps a value T stored in a thread.

This type works similar in nature to Fragile<T> and exposes the same interface. The difference is that whereas Fragile<T> has its destructor called in the thread where the value was sent, a Sticky<T> that is moved to another thread will have the internal destructor called when the originating thread tears down.

As this uses TLS internally the general rules about the platform limitations of destructors for TLS apply.

Methods

impl<T> Sticky<T>[src]

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

Creates a new Sticky wrapping a value.

The value that is moved into the Sticky can be non Send and will be anchored to the thread that created the object. If the sticky 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 Sticky, 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 Sticky, 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 Sticky 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 Sticky<T>[src]

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

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

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

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

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

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

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

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

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

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

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

Auto Trait Implementations

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

impl<T> Unpin for Sticky<T>

impl<T> UnwindSafe for Sticky<T> where
    T: RefUnwindSafe

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.