SingleThreadCell

Struct SingleThreadCell 

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

A mutable memory location. Can only be accessed by the owner thread.

If you access the cell from a different thread, the thread will be panicked.

Implementations§

Source§

impl<T> SingleThreadCell<T>

Source

pub fn new(val: T) -> Self

Creates a new Cell containing the given value.

The owner thread will be the same as the caller thread.

Source

pub fn set(&self, value: T)

Set the contained value

§Panics

This function will panic if access from different thread

Source

pub fn replace(&self, value: T) -> T

Replace the contained value, and return the old contained value.

§Panics

This function will panic if access from different thread

Source§

impl<T: Copy> SingleThreadCell<T>

Source

pub fn get(&self) -> T

Returns a copy of the contained value.

Trait Implementations§

Source§

impl<T: Default> Default for SingleThreadCell<T>

Source§

fn default() -> Self

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

impl<T> SingleThreadType for SingleThreadCell<T>

Source§

fn get_owner_thread_id(&self) -> ThreadId

Get the owner thread that owns this type.

Source§

fn check_thread_panic(&self)

Check the current thread and panic if not same.
Source§

fn check_same_thread(&self) -> bool

Source§

impl<T> Sync for SingleThreadCell<T>

Auto Trait Implementations§

§

impl<T> !Freeze for SingleThreadCell<T>

§

impl<T> !RefUnwindSafe for SingleThreadCell<T>

§

impl<T> Send for SingleThreadCell<T>
where T: Send,

§

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

§

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

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.