dfir_pipes/pull/
either.rs1use core::pin::Pin;
2
3use itertools::Either;
4
5use crate::pull::{FusedPull, Pull, PullStep};
6use crate::{Context, Toggle};
7
8impl<L, R> Pull for Either<L, R>
9where
10 L: Pull,
11 R: Pull<Item = L::Item, Meta = L::Meta>,
12{
13 type Ctx<'ctx> = <L::Ctx<'ctx> as Context<'ctx>>::Merged<R::Ctx<'ctx>>;
14
15 type Item = L::Item;
16 type Meta = L::Meta;
17 type CanPend = <L::CanPend as Toggle>::Or<R::CanPend>;
18 type CanEnd = <L::CanEnd as Toggle>::Or<R::CanEnd>;
19
20 fn pull(
21 self: Pin<&mut Self>,
22 ctx: &mut Self::Ctx<'_>,
23 ) -> PullStep<Self::Item, Self::Meta, Self::CanPend, Self::CanEnd> {
24 match self.as_pin_mut() {
25 Either::Left(left) => left
26 .pull(<L::Ctx<'_> as Context<'_>>::unmerge_self(ctx))
27 .convert_into(),
28 Either::Right(right) => right
29 .pull(<L::Ctx<'_> as Context<'_>>::unmerge_other(ctx))
30 .convert_into(),
31 }
32 }
33
34 fn size_hint(&self) -> (usize, Option<usize>) {
35 match self.as_ref() {
36 Either::Left(left) => left.size_hint(),
37 Either::Right(right) => right.size_hint(),
38 }
39 }
40}
41
42impl<L, R> FusedPull for Either<L, R>
43where
44 L: FusedPull,
45 R: FusedPull<Item = L::Item, Meta = L::Meta>,
46{
47}