Struct Fuse

#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Fuse<Fut> { /* private fields */ }

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 core::pin::pin;

use futures::channel::mpsc;
use futures::future::{Fuse, FusedFuture, FutureExt};
use futures::select;
use futures::stream::StreamExt;

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();
let mut foo_printer = pin!(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
    }
}
# });

Trait Implementations

impl<'__pin, Fut> Unpin for Fuse<Fut> where PinnedFieldsOf<__Origin<'__pin, Fut>>: Unpin,

impl<Fut: Debug> Debug for Fuse<Fut>

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

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

fn is_terminated(&self) -> bool

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

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

Auto Trait Implementations

impl<Fut> Freeze for Fuse<Fut> where Option<Fut>: Freeze,

impl<Fut> RefUnwindSafe for Fuse<Fut> where Option<Fut>: RefUnwindSafe,

impl<Fut> Send for Fuse<Fut> where Option<Fut>: Send,

impl<Fut> Sync for Fuse<Fut> where Option<Fut>: Sync,

impl<Fut> UnsafeUnpin for Fuse<Fut> where Option<Fut>: UnsafeUnpin,

impl<Fut> UnwindSafe for Fuse<Fut> where Option<Fut>: UnwindSafe,

Blanket Implementations

impl<F> IntoFuture for Fuse<Fut> 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 Fuse<Fut> 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<Fut> TryFutureExt for Fuse<Fut> where Fut: TryFuture + ?Sized,

impl<T> Any for Fuse<Fut> where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for Fuse<Fut> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for Fuse<Fut> where T: ?Sized,

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

impl<T> From<T> for Fuse<Fut>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> FutureExt for Fuse<Fut> where T: Future + ?Sized,

impl<T, U> Into<U> for Fuse<Fut> 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 Fuse<Fut> where U: Into<T>,

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

impl<T, U> TryInto<U> for Fuse<Fut> where U: TryFrom<T>,

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