[][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> From<T> for Sticky<T>[src]

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

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

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

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0
[src]

This method tests for !=.

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

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

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

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

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

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

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

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

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

Blanket Implementations

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

impl<T> From for T[src]

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

type Owned = T

impl<T> ToString for T where
    T: Display + ?Sized
[src]

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

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

The type returned in the event of a conversion error.