Struct pros_core::task::local::LocalKey

source ·
pub struct LocalKey<T: 'static> { /* private fields */ }
Expand description

A TLS key that owns its data. Can be created with the os_task_local macro.

Implementations§

source§

impl<T: 'static> LocalKey<T>

source

pub const fn new(init: fn() -> T) -> Self

Creates a new local key that lazily initializes its data. init is called to initialize the data when it is first accessed from a new thread.

source

pub fn with<F, R>(&'static self, f: F) -> R
where F: FnOnce(&'static T) -> R,

Passes a reference to the value of this key to the given closure. If the value has not been initialized yet, it will be initialized.

source§

impl<T: 'static> LocalKey<Cell<T>>

source

pub fn set(&'static self, value: T)

Sets or initializes the value of this key.

If the value was already initialized, it is overwritten. If the value was not initialized, it is initialized with value.

source

pub fn get(&'static self) -> T
where T: Copy,

Gets a copy of the value in this TLS key.

source

pub fn take(&'static self) -> T
where T: Default,

Takes the value out of this TLS key, replacing it with the Default value.

source

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

Replaces the value in this TLS key with the given one, returning the old value.

source§

impl<T: 'static> LocalKey<RefCell<T>>

source

pub fn with_borrow<F, R>(&'static self, f: F) -> R
where F: FnOnce(&T) -> R,

Acquires a reference to the contained value, initializing it if required.

§Panics

Panics if the value is currently mutably borrowed.

source

pub fn with_borrow_mut<F, R>(&'static self, f: F) -> R
where F: FnOnce(&mut T) -> R,

Acquires a mutable reference to the contained value, initializing it if required.

§Panics

Panics if the value is currently borrowed.

source

pub fn set(&'static self, value: T)

Sets or initializes the value of this key, without running the initializer.

§Panics

Panics if the value is currently borrowed.

source

pub fn take(&'static self) -> T
where T: Default,

Takes the value out of this TLS key, replacing it with the Default value.

§Panics

Panics if the value is currently borrowed.

source

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

Replaces the value in this TLS key with the given one, returning the old value.

§Panics

Panics if the value is currently borrowed.

Trait Implementations§

source§

impl<T: Debug + 'static> Debug for LocalKey<T>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for LocalKey<T>

§

impl<T> !RefUnwindSafe for LocalKey<T>

§

impl<T> Send for LocalKey<T>

§

impl<T> Sync for LocalKey<T>

§

impl<T> Unpin for LocalKey<T>

§

impl<T> UnwindSafe for LocalKey<T>

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>,

§

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>,

§

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.