async_rs/util/
future.rs

1use std::{
2    fmt,
3    future::Future,
4    pin::Pin,
5    task::{self, Context, Poll},
6};
7
8/// Wrap a Future to discard its output
9pub struct UnitFuture<F: Future + Unpin>(pub F);
10
11impl<F: Future + Unpin> Future for UnitFuture<F> {
12    type Output = ();
13
14    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
15        task::ready!(Pin::new(&mut self.0).poll(cx));
16        Poll::Ready(())
17    }
18}
19
20impl<F: Future + Unpin> fmt::Debug for UnitFuture<F> {
21    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
22        f.debug_tuple("UnitFuture").finish()
23    }
24}