Skip to main content

locode_engine/
sink.rs

1//! Where the loop's `stream-json` events go (ADR-0014).
2
3use locode_protocol::Event;
4
5/// A sink for the loop's [`Event`]s. `&mut self` so a writer sink can buffer/flush;
6/// object-safe so `locode-exec` can pick one at runtime by `--output-format`.
7pub trait EventSink: Send {
8    /// Receive one event (called in emission order).
9    fn emit(&mut self, event: Event);
10}
11
12/// Drops every event — for the `json`/`text` output modes that only want the report.
13pub struct NullSink;
14
15impl EventSink for NullSink {
16    fn emit(&mut self, _event: Event) {}
17}
18
19/// Forwards each event to a closure — e.g. a JSONL stdout writer for `stream-json`,
20/// or a `Vec`-pushing closure in tests.
21pub struct FnSink<F: FnMut(Event) + Send>(pub F);
22
23impl<F: FnMut(Event) + Send> EventSink for FnSink<F> {
24    fn emit(&mut self, event: Event) {
25        (self.0)(event);
26    }
27}