TaskLocal

Struct TaskLocal 

Source
pub struct TaskLocal<T> {
    inner: UnsafeCell<T>,
}
Expand description

A cell type for task-local data that is only accessed by the hart currently executing the task.

§Safety

This type uses UnsafeCell internally and is Sync so it can live inside Task (which is Send + Sync). The safety invariant is:

  • Only the hart that is currently running this task may access the contents. Because a task is scheduled on exactly one hart at a time, there is no concurrent access and no lock is needed.
  • During clone_task, the parent accesses its own TaskLocal fields (safe – it is the running hart) and writes to the child’s TaskLocal fields (safe – the child has not been added to the scheduler yet, so no other hart can touch it).

Fields§

§inner: UnsafeCell<T>

Implementations§

Source§

impl<T> TaskLocal<T>

Source

pub fn new(value: T) -> Self

Create a new TaskLocal with the given value.

Source

pub unsafe fn get(&self) -> &T

Get an immutable reference to the contained value.

§Safety

The caller must be the hart currently executing the owning task, or the task must not yet be visible to the scheduler.

Source

pub unsafe fn get_mut(&self) -> &mut T

Get a mutable reference to the contained value.

§Safety

The caller must be the hart currently executing the owning task, or the task must not yet be visible to the scheduler.

Trait Implementations§

Source§

impl<T> Sync for TaskLocal<T>

Auto Trait Implementations§

§

impl<T> !Freeze for TaskLocal<T>

§

impl<T> !RefUnwindSafe for TaskLocal<T>

§

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

§

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

§

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

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

Performs the conversion.
§

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.
§

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

Performs the conversion.