Struct ReusableBoxFuture

pub struct ReusableBoxFuture<'a, T> { /* private fields */ }

A reusable Pin<Box<dyn Future<Output = T> + Send + 'a>>.

This type lets you replace the future stored in the box without reallocating when the size and alignment permits this.

Implementations

impl<'a, T> ReusableBoxFuture<'a, T>

fn new<F>(future: F) -> Self
where
    F: Future<Output = T> + Send + 'a,

Create a new ReusableBoxFuture<T> containing the provided future.

fn set<F>(&mut self, future: F)
where
    F: Future<Output = T> + Send + 'a,

Replace the future currently stored in this box.

This reallocates if and only if the layout of the provided future is different from the layout of the currently stored future.

fn try_set<F>(&mut self, future: F) -> Result<(), F>
where
    F: Future<Output = T> + Send + 'a,

Replace the future currently stored in this box.

This function never reallocates, but returns an error if the provided future has a different size or alignment from the currently stored future.

fn get_pin(&mut self) -> Pin<&mut dyn Future<Output = T> + Send>

Get a pinned reference to the underlying future.

fn poll(&mut self, cx: &mut Context<'_>) -> Poll<T>

Poll the future stored inside this box.

Trait Implementations

impl<T> Debug for ReusableBoxFuture<'_, T>

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

impl<T> Future for ReusableBoxFuture<'_, T>

type Output = T;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T>

Poll the future stored inside this box.

impl<T> Sync for ReusableBoxFuture<'_, T>

Auto Trait Implementations

impl<'a, T> !RefUnwindSafe for ReusableBoxFuture<'a, T>

impl<'a, T> !UnwindSafe for ReusableBoxFuture<'a, T>

impl<'a, T> Freeze for ReusableBoxFuture<'a, T> where Pin<Box<dyn Future<Output = T> + Send + 'a>>: Freeze,

impl<'a, T> Send for ReusableBoxFuture<'a, T> where Pin<Box<dyn Future<Output = T> + Send + 'a>>: Send,

impl<'a, T> Unpin for ReusableBoxFuture<'a, T> where Pin<Box<dyn Future<Output = T> + Send + 'a>>: Unpin,

impl<'a, T> UnsafeUnpin for ReusableBoxFuture<'a, T> where Pin<Box<dyn Future<Output = T> + Send + 'a>>: UnsafeUnpin,

Blanket Implementations

impl<F> IntoFuture for ReusableBoxFuture<'a, T> where F: Future,

type Output = <F as Future>::Output;
type IntoFuture = F;
fn into_future(self) -> <F as IntoFuture>::IntoFuture

impl<F, T, E> TryFuture for ReusableBoxFuture<'a, T> where F: Future<Output = Result<T, E>> + ?Sized,

type Ok = T;
type Error = E;
fn try_poll(self: Pin<&mut F>, cx: &mut Context<'_>) -> Poll<<F as Future>::Output>

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

fn type_id(&self) -> TypeId

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

fn borrow(&self) -> &T

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

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

impl<T> From<T> for ReusableBoxFuture<'a, T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> FutureExt for ReusableBoxFuture<'a, T> where T: Future + ?Sized,

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

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