[][src]Trait smol::future::FutureExt

pub trait FutureExt: Future {
    fn or<F>(self, other: F) -> Or<Self, F>

Notable traits for Or<F1, F2>

impl<T, F1, F2> Future for Or<F1, F2> where
    F1: Future<Output = T>,
    F2: Future<Output = T>, 
type Output = T;

    where
        F: Future<Output = Self::Output>
, { ... }
fn boxed(
        self
    ) -> Pin<Box<dyn Future<Output = Self::Output> + 'static + Send>>

Notable traits for Pin<P>

impl<P> Future for Pin<P> where
    P: Unpin + DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;

    where
        Self: Send + 'static
, { ... }
fn boxed_local(
        self
    ) -> Pin<Box<dyn Future<Output = Self::Output> + 'static>>

Notable traits for Pin<P>

impl<P> Future for Pin<P> where
    P: Unpin + DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;

    where
        Self: 'static
, { ... } }

Extension trait for Future.

Provided methods

fn or<F>(self, other: F) -> Or<Self, F>

Notable traits for Or<F1, F2>

impl<T, F1, F2> Future for Or<F1, F2> where
    F1: Future<Output = T>,
    F2: Future<Output = T>, 
type Output = T;
where
    F: Future<Output = Self::Output>, 

Returns the result of self or other future, preferring self if both are ready.

If you need to treat the two futures fairly without a preference for either, use the race() function instead.

Examples

use futures_lite::*;
use futures_lite::future::{pending, ready};

assert_eq!(ready(1).or(pending()).await, 1);
assert_eq!(pending().or(ready(2)).await, 2);

// The first future wins.
assert_eq!(ready(1).or(ready(2)).await, 1);

fn boxed(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'static + Send>>

Notable traits for Pin<P>

impl<P> Future for Pin<P> where
    P: Unpin + DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;
where
    Self: Send + 'static, 

Boxes the future and changes its type to dyn Future<Output = T> + Send.

Examples

use futures_lite::*;

let a = future::ready('a');
let b = future::pending();

// Futures of different types can be stored in
// the same collection when they are boxed:
let futures = vec![a.boxed(), b.boxed()];

fn boxed_local(self) -> Pin<Box<dyn Future<Output = Self::Output> + 'static>>

Notable traits for Pin<P>

impl<P> Future for Pin<P> where
    P: Unpin + DerefMut,
    <P as Deref>::Target: Future
type Output = <<P as Deref>::Target as Future>::Output;
where
    Self: 'static, 

Boxes the future and changes its type to dyn Future<Output = T>.

Examples

use futures_lite::*;

let a = future::ready('a');
let b = future::pending();

// Futures of different types can be stored in
// the same collection when they are boxed:
let futures = vec![a.boxed_local(), b.boxed_local()];
Loading content...

Implementors

impl<F> FutureExt for F where
    F: Future + ?Sized
[src]

Loading content...