pub enum FlexFuture<T> {
Ready(Ready<T>),
Pending(Pending<T>),
Generic(Pin<Box<dyn Future<Output = T>>>),
}Expand description
Future that either returns a precomputed value or delegates to a heap-allocated, type-erased future.
FlexFuture works as a selective wrapper for std::future::Ready,
std::future::Pending, and a generic future in a Box. When a function
needs to return a future, it can use FlexFuture to possibly avoid heap
allocation if the future is already known to be ready.
This type does not have a lifetime parameter, so the contained future must
have a 'static lifetime. This is because FlexFuture is also used in
SharedSystem, which performs dynamic lifetime
checking to access its internal state guarded by a RefCell. Instead of
borrowing the system, the future must share ownership of the system to keep
it alive until the future is resolved.
Variants§
Ready(Ready<T>)
Future that is already ready with a value
Pending(Pending<T>)
Future that is pending and will never resolve
Generic(Pin<Box<dyn Future<Output = T>>>)
Heap-allocated, type-erased future
Implementations§
Source§impl<T> FlexFuture<T>
impl<T> FlexFuture<T>
Sourcepub fn boxed<F>(f: F) -> Selfwhere
F: Future<Output = T> + 'static,
pub fn boxed<F>(f: F) -> Selfwhere
F: Future<Output = T> + 'static,
Creates a new FlexFuture from any future.
This function allocates memory for the future. If the future is already
allocated on the heap, use FlexFuture::from instead.
Sourcepub fn into_boxed(self) -> Pin<Box<dyn Future<Output = T>>>where
T: 'static,
pub fn into_boxed(self) -> Pin<Box<dyn Future<Output = T>>>where
T: 'static,
Converts this FlexFuture into a Pin<Box<dyn Future<Output = T>>.
Trait Implementations§
Source§impl<T: Debug> Debug for FlexFuture<T>
impl<T: Debug> Debug for FlexFuture<T>
Source§impl<T: 'static> From<FlexFuture<T>> for Pin<Box<dyn Future<Output = T>>>
impl<T: 'static> From<FlexFuture<T>> for Pin<Box<dyn Future<Output = T>>>
Source§fn from(future: FlexFuture<T>) -> Self
fn from(future: FlexFuture<T>) -> Self
Source§impl<T> From<Pending<T>> for FlexFuture<T>
impl<T> From<Pending<T>> for FlexFuture<T>
Source§impl<T> From<Ready<T>> for FlexFuture<T>
impl<T> From<Ready<T>> for FlexFuture<T>
Source§impl<T> From<T> for FlexFuture<T>
impl<T> From<T> for FlexFuture<T>
Source§impl<T> Future for FlexFuture<T>
impl<T> Future for FlexFuture<T>
Auto Trait Implementations§
impl<T> Freeze for FlexFuture<T>where
T: Freeze,
impl<T> !RefUnwindSafe for FlexFuture<T>
impl<T> !Send for FlexFuture<T>
impl<T> !Sync for FlexFuture<T>
impl<T> Unpin for FlexFuture<T>
impl<T> !UnwindSafe for FlexFuture<T>
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> FutureExt for T
impl<T> FutureExt for T
Source§fn map<U, F>(self, f: F) -> Map<Self, F>
fn map<U, F>(self, f: F) -> Map<Self, F>
Source§fn map_into<U>(self) -> MapInto<Self, U>
fn map_into<U>(self) -> MapInto<Self, U>
Source§fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
fn then<Fut, F>(self, f: F) -> Then<Self, Fut, F>
f. Read moreSource§fn left_future<B>(self) -> Either<Self, B>
fn left_future<B>(self) -> Either<Self, B>
Source§fn right_future<A>(self) -> Either<A, Self>
fn right_future<A>(self) -> Either<A, Self>
Source§fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
fn into_stream(self) -> IntoStream<Self>where
Self: Sized,
Source§fn flatten(self) -> Flatten<Self>
fn flatten(self) -> Flatten<Self>
Source§fn flatten_stream(self) -> FlattenStream<Self>
fn flatten_stream(self) -> FlattenStream<Self>
Source§fn fuse(self) -> Fuse<Self>where
Self: Sized,
fn fuse(self) -> Fuse<Self>where
Self: Sized,
poll will never again be called once it has
completed. This method can be used to turn any Future into a
FusedFuture. Read moreSource§fn inspect<F>(self, f: F) -> Inspect<Self, F>
fn inspect<F>(self, f: F) -> Inspect<Self, F>
Source§fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
fn catch_unwind(self) -> CatchUnwind<Self>where
Self: Sized + UnwindSafe,
Source§fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
fn boxed<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + Send + 'a>>
Source§fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
fn boxed_local<'a>(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'a>>where
Self: Sized + 'a,
Source§fn unit_error(self) -> UnitError<Self>where
Self: Sized,
fn unit_error(self) -> UnitError<Self>where
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = ()>.Source§fn never_error(self) -> NeverError<Self>where
Self: Sized,
fn never_error(self) -> NeverError<Self>where
Self: Sized,
Future<Output = T> into a
TryFuture<Ok = T, Error = Never>.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