futures_util/future/
empty.rs

1//! Definition of the Empty combinator, a future that's never ready.
2
3use core::marker;
4
5use futures_core::{Future, Poll, Async};
6use futures_core::task;
7
8/// A future which is never resolved.
9///
10/// This future can be created with the `empty` function.
11#[derive(Debug)]
12#[must_use = "futures do nothing unless polled"]
13pub struct Empty<T, E> {
14    _data: marker::PhantomData<(T, E)>,
15}
16
17/// Creates a future which never resolves, representing a computation that never
18/// finishes.
19///
20/// The returned future will forever return `Async::Pending`.
21pub fn empty<T, E>() -> Empty<T, E> {
22    Empty { _data: marker::PhantomData }
23}
24
25impl<T, E> Future for Empty<T, E> {
26    type Item = T;
27    type Error = E;
28
29    fn poll(&mut self, _: &mut task::Context) -> Poll<T, E> {
30        Ok(Async::Pending)
31    }
32}