Struct ContextBuilder

pub struct ContextBuilder<'a> { pub(in ::task::wake) waker: &'a Waker, pub(in ::task::wake) local_waker: &'a LocalWaker, pub(in ::task::wake) ext: ExtData<'a>, pub(in ::task::wake) _marker: PhantomData<fn(&'a ()) -> &'a ()>, pub(in ::task::wake) _marker2: PhantomData<*mut ()> }

A Builder used to construct a Context instance with support for LocalWaker.

Examples

#![feature(local_waker)]
use std::task::{ContextBuilder, LocalWaker, Waker, Poll};
use std::future::Future;

let local_waker = LocalWaker::noop();
let waker = Waker::noop();

let mut cx = ContextBuilder::from_waker(&waker)
    .local_waker(&local_waker)
    .build();

let mut future = std::pin::pin!(async { 20 });
let poll = future.as_mut().poll(&mut cx);
assert_eq!(poll, Poll::Ready(20));

Fields

waker: &'a Waker
local_waker: &'a LocalWaker
ext: ExtData<'a>
_marker: PhantomData<fn(&'a ()) -> &'a ()>
_marker2: PhantomData<*mut ()>

Implementations

impl<'a> ContextBuilder<'a>

const fn from_waker(waker: &'a Waker) -> Self

Creates a ContextBuilder from a Waker.

const fn from(cx: &'a mut Context<'_>) -> Self

Creates a ContextBuilder from an existing Context.

const fn waker(self, waker: &'a Waker) -> Self

Sets the value for the waker on Context.

const fn local_waker(self, local_waker: &'a LocalWaker) -> Self

Sets the value for the local waker on Context.

const fn ext(self, data: &'a mut dyn Any) -> Self

Sets the value for the extension data on Context.

const fn build(self) -> Context<'a>

Builds the Context.

Trait Implementations

impl<'a> Debug for ContextBuilder<'a>

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

Auto Trait Implementations

impl<'a> !RefUnwindSafe for ContextBuilder<'a>

impl<'a> !Send for ContextBuilder<'a>

impl<'a> !Sync for ContextBuilder<'a>

impl<'a> !UnwindSafe for ContextBuilder<'a>

impl<'a> Freeze for ContextBuilder<'a>

impl<'a> Unpin for ContextBuilder<'a>

impl<'a> UnsafeUnpin for ContextBuilder<'a>

Blanket Implementations

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

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for ContextBuilder<'a> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for ContextBuilder<'a> where T: ?Sized,

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

impl<T> From<T> for ContextBuilder<'a>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> SizeHint for ContextBuilder<'a> where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for ContextBuilder<'a>

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

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for ContextBuilder<'a> where U: TryFrom<T>,

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