[−][src]Struct fragile::Sticky
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]
fn cmp(&self, other: &Sticky<T>) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<T: PartialEq> PartialEq<Sticky<T>> for Sticky<T>
[src]
impl<T: PartialOrd> PartialOrd<Sticky<T>> for Sticky<T>
[src]
fn partial_cmp(&self, other: &Sticky<T>) -> Option<Ordering>
[src]
fn lt(&self, other: &Sticky<T>) -> bool
[src]
fn le(&self, other: &Sticky<T>) -> bool
[src]
fn gt(&self, other: &Sticky<T>) -> bool
[src]
fn ge(&self, other: &Sticky<T>) -> bool
[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,
T: RefUnwindSafe,
impl<T> Unpin for Sticky<T>
impl<T> UnwindSafe for Sticky<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[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]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,