Skip to main content

dfir_pipes/pull/
empty.rs

1use core::marker::PhantomData;
2
3use crate::pull::{FusedPull, Pull, PullStep, fuse_self};
4use crate::{No, Yes};
5
6/// A pull that yields no items and immediately ends.
7#[must_use = "`Pull`s do nothing unless polled"]
8#[derive(Clone, Debug)]
9pub struct Empty<Item> {
10    _marker: PhantomData<Item>,
11}
12
13impl<Item> Default for Empty<Item> {
14    fn default() -> Self {
15        Self {
16            _marker: PhantomData,
17        }
18    }
19}
20
21impl<Item> Pull for Empty<Item> {
22    type Ctx<'ctx> = ();
23
24    type Item = Item;
25    type Meta = ();
26    type CanPend = No;
27    type CanEnd = Yes;
28
29    fn pull(
30        self: core::pin::Pin<&mut Self>,
31        _ctx: &mut Self::Ctx<'_>,
32    ) -> PullStep<Self::Item, Self::Meta, Self::CanPend, Self::CanEnd> {
33        PullStep::Ended(Yes)
34    }
35
36    fn size_hint(&self) -> (usize, Option<usize>) {
37        (0, Some(0))
38    }
39
40    fuse_self!();
41}
42
43impl<Item> FusedPull for Empty<Item> {}