Struct Fuse

struct Fuse<Fut> { ... }

Future for the fuse method.

Implementations

impl<Fut: Future> Fuse<Fut>

fn terminated() -> Self

Creates a new Fuse-wrapped future which is already terminated.

This can be useful in combination with looping and the select! macro, which bypasses terminated futures.

Examples

# futures::executor::block_on(async {
use futures::channel::mpsc;
use futures::future::{Fuse, FusedFuture, FutureExt};
use futures::select;
use futures::stream::StreamExt;
use futures::pin_mut;

let (sender, mut stream) = mpsc::unbounded();

// Send a few messages into the stream
sender.unbounded_send(()).unwrap();
sender.unbounded_send(()).unwrap();
drop(sender);

// Use `Fuse::terminated()` to create an already-terminated future
// which may be instantiated later.
let foo_printer = Fuse::terminated();
pin_mut!(foo_printer);

loop {
    select! {
        _ = foo_printer => {},
        () = stream.select_next_some() => {
            if !foo_printer.is_terminated() {
                println!("Foo is already being printed!");
            } else {
                foo_printer.set(async {
                    // do some other async operations
                    println!("Printing foo from `foo_printer` future");
                }.fuse());
            }
        },
        complete => break, // `foo_printer` is terminated and the stream is done
    }
}
# });

impl<'__pin, Fut> Unpin for Fuse<Fut>

impl<F> IntoFuture for Fuse<Fut>

fn into_future(self: Self) -> <F as IntoFuture>::IntoFuture

impl<F, T, E> TryFuture for Fuse<Fut>

fn try_poll(self: Pin<&mut F>, cx: &mut Context<'_>) -> Poll<<F as Future>::Output>

impl<Fut> Freeze for Fuse<Fut>

impl<Fut> RefUnwindSafe for Fuse<Fut>

impl<Fut> Send for Fuse<Fut>

impl<Fut> Sync for Fuse<Fut>

impl<Fut> TryFutureExt for Fuse<Fut>

impl<Fut> UnsafeUnpin for Fuse<Fut>

impl<Fut> UnwindSafe for Fuse<Fut>

impl<Fut: $crate::fmt::Debug> Debug for Fuse<Fut>

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

impl<Fut: Future> FusedFuture for Fuse<Fut>

fn is_terminated(self: &Self) -> bool

impl<Fut: Future> Future for Fuse<Fut>

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<<Fut as >::Output>

impl<T> Any for Fuse<Fut>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Fuse<Fut>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Fuse<Fut>

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

impl<T> From for Fuse<Fut>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> FutureExt for Fuse<Fut>

impl<T, U> Into for Fuse<Fut>

fn into(self: 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 for Fuse<Fut>

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

impl<T, U> TryInto for Fuse<Fut>

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