pub struct ThreadBound<T> { /* private fields */ }
Expand description

ThreadBound is a Sync-maker and Send-maker that allows accessing a value of type T only from the original thread on which the ThreadBound was constructed.

Refer to the crate-level documentation for a usage example.

Implementations§

source§

impl<T> ThreadBound<T>

source

pub fn new(value: T) -> Self

Binds a value to the current thread. The wrapper can be sent around to other threads, but no other threads will be able to access the underlying value.

source

pub fn get_ref(&self) -> Option<&T>

Accesses a reference to the underlying value if this is its original thread, otherwise None.

source

pub fn get_mut(&mut self) -> Option<&mut T>

Accesses a mutable reference to the underlying value if this is its original thread, otherwise None.

source

pub fn into_inner(self) -> Option<T>

Extracts ownership of the underlying value if this is its original thread, otherwise None.

Trait Implementations§

source§

impl<T: Debug> Debug for ThreadBound<T>

source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Default> Default for ThreadBound<T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T: Copy> Send for ThreadBound<T>

source§

impl<T> Sync for ThreadBound<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for ThreadBound<T>where T: RefUnwindSafe,

§

impl<T> Unpin for ThreadBound<T>where T: Unpin,

§

impl<T> UnwindSafe for ThreadBound<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.