Skip to main content

dfir_rs/compiled/push/
demux_enum.rs

1// TODO(mingwei): Move this & derive macro to separate crate ([`sinktools`])
2use std::pin::Pin;
3
4use dfir_pipes::push::{Push, PushStep};
5use pin_project_lite::pin_project;
6
7use crate::util::demux_enum::DemuxEnumPush;
8
9pin_project! {
10    /// Special push operator for the `demux_enum` operator.
11    #[must_use = "`Push`es do nothing unless items are pushed into them"]
12    pub struct DemuxEnum<Outputs> {
13        outputs: Outputs,
14    }
15}
16
17impl<Outputs> DemuxEnum<Outputs> {
18    /// Creates with the given `Outputs`.
19    pub const fn new(outputs: Outputs) -> Self {
20        Self { outputs }
21    }
22}
23
24impl<Outputs, Item, Meta: Copy> Push<Item, Meta> for DemuxEnum<Outputs>
25where
26    Item: DemuxEnumPush<Outputs, Meta>,
27{
28    type Ctx<'ctx> = <Item as DemuxEnumPush<Outputs, Meta>>::Ctx<'ctx>;
29
30    type CanPend = <Item as DemuxEnumPush<Outputs, Meta>>::CanPend;
31
32    fn poll_ready(self: Pin<&mut Self>, ctx: &mut Self::Ctx<'_>) -> PushStep<Self::CanPend> {
33        Item::poll_ready(self.project().outputs, ctx)
34    }
35
36    fn start_send(self: Pin<&mut Self>, item: Item, meta: Meta) {
37        Item::start_send(item, meta, self.project().outputs);
38    }
39
40    fn poll_flush(self: Pin<&mut Self>, ctx: &mut Self::Ctx<'_>) -> PushStep<Self::CanPend> {
41        Item::poll_flush(self.project().outputs, ctx)
42    }
43}