pub struct Context<'a> { /* private fields */ }
Expand description
Information about the currently-running task.
Contexts are always tied to the stack, since they are set up specifically
when performing a single poll
step on a task.
Implementations§
Source§impl<'a> Context<'a>
impl<'a> Context<'a>
Sourcepub fn without_spawn(map: &'a mut LocalMap, waker: &'a Waker) -> Context<'a>
pub fn without_spawn(map: &'a mut LocalMap, waker: &'a Waker) -> Context<'a>
Create a new task context without the ability to spawn
.
This constructor should only be used for no_std
contexts, where the
standard Executor
trait is not available.
Sourcepub fn waker(&self) -> &Waker
pub fn waker(&self) -> &Waker
Get the Waker
associated with the current task.
The waker can subsequently be used to wake up the task when some event of interest has happened.
Sourcepub fn with_waker<'b>(&'b mut self, waker: &'b Waker) -> Context<'b>
pub fn with_waker<'b>(&'b mut self, waker: &'b Waker) -> Context<'b>
Produce a context like the current one, but using the given waker instead.
This advanced method is primarily used when building “internal schedulers” within a task, where you want to provide some customized wakeup logic.
Sourcepub fn with_locals<'b>(&'b mut self, map: &'b mut LocalMap) -> Context<'b>
pub fn with_locals<'b>(&'b mut self, map: &'b mut LocalMap) -> Context<'b>
Produce a context like the current one, but using the given task locals instead.
This advanced method is primarily used when building “internal schedulers” within a task.
Source§impl<'a> Context<'a>
impl<'a> Context<'a>
Sourcepub fn new(
map: &'a mut LocalMap,
waker: &'a Waker,
executor: &'a mut dyn Executor,
) -> Context<'a>
pub fn new( map: &'a mut LocalMap, waker: &'a Waker, executor: &'a mut dyn Executor, ) -> Context<'a>
Create a new task context.
Task contexts are equipped with:
- Task-local data
- A means of waking the task
- A means of spawning new tasks, i.e. an executor
Sourcepub fn executor(&mut self) -> &mut dyn Executor
pub fn executor(&mut self) -> &mut dyn Executor
Get the default executor associated with this task, if any
This method is useful primarily if you want to explicitly handle spawn failures.
Sourcepub fn spawn<F>(&mut self, f: F)
pub fn spawn<F>(&mut self, f: F)
Spawn a future onto the default executor.
§Panics
This method will panic if the default executor is unable to spawn or does not exist.
To handle executor errors, use executor() instead.
Sourcepub fn with_executor<'b>(
&'b mut self,
executor: &'b mut dyn Executor,
) -> Context<'b>
pub fn with_executor<'b>( &'b mut self, executor: &'b mut dyn Executor, ) -> Context<'b>
Produce a context like the current one, but using the given executor instead.
This advanced method is primarily used when building “internal schedulers” within a task.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for Context<'a>
impl<'a> !RefUnwindSafe for Context<'a>
impl<'a> !Send for Context<'a>
impl<'a> !Sync for Context<'a>
impl<'a> Unpin for Context<'a>
impl<'a> !UnwindSafe for Context<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more