dfir_rs/util/
demux_enum.rs1use std::task::{Context, Poll};
4
5pub use dfir_macro::DemuxEnum;
6use dfir_pipes::Toggle;
7use dfir_pipes::push::PushStep;
8
9#[diagnostic::on_unimplemented(
16 note = "ensure there is exactly one output for each enum variant.",
17 note = "ensure that the type for each output is a tuple of the field for the variant: `()`, `(a,)`, or `(a, b, ...)`."
18)]
19pub trait DemuxEnumSink<Outputs>: DemuxEnumBase {
20 type Error;
22
23 fn poll_ready(outputs: &mut Outputs, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
25
26 fn start_send(self, outputs: &mut Outputs) -> Result<(), Self::Error>;
28
29 fn poll_flush(outputs: &mut Outputs, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
31
32 fn poll_close(outputs: &mut Outputs, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>;
34}
35
36#[diagnostic::on_unimplemented(
43 note = "ensure there is exactly one output for each enum variant.",
44 note = "ensure that the type for each output is a tuple of the field for the variant: `()`, `(a,)`, or `(a, b, ...)`."
45)]
46pub trait DemuxEnumPush<Outputs, Meta: Copy>: DemuxEnumBase {
47 type Ctx<'ctx>: dfir_pipes::Context<'ctx>;
49
50 type CanPend: Toggle;
53
54 fn poll_ready(outputs: &mut Outputs, ctx: &mut Self::Ctx<'_>) -> PushStep<Self::CanPend>;
56
57 fn start_send(self, meta: Meta, outputs: &mut Outputs);
59
60 fn poll_flush(outputs: &mut Outputs, ctx: &mut Self::Ctx<'_>) -> PushStep<Self::CanPend>;
62}
63#[diagnostic::on_unimplemented(
65 note = "requires that the enum have only one variant.",
66 note = "ensure there are no missing outputs; there must be exactly one output for each enum variant."
67)]
68pub trait SingleVariant: DemuxEnumBase {
69 type Output;
71 fn single_variant(self) -> Self::Output;
73}
74
75#[diagnostic::on_unimplemented(note = "use `#[derive(dfir_rs::DemuxEnum)]`")]
77pub trait DemuxEnumBase {}