futures::task

Struct Context

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

Source

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.

Source

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.

Source

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.

Source

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>

Source

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
Source

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.

Source

pub fn spawn<F>(&mut self, f: F)
where F: Future<Item = (), Error = Never> + 'static + Send,

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.

Source

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§

Source§

impl<'a> Debug for Context<'a>

Source§

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

Formats the value using the given formatter. Read more

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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