wick_component/
outputs.rs

1use wick_packet::{OutputIterator, Port};
2
3/// Trait for operation outputs to handle situations where packets need to be sent to all output streams.
4pub trait Broadcast {
5  /// Broadcast an open bracket to all output streams.
6  fn broadcast_open(&mut self) {
7    for output in self.outputs_mut() {
8      output.open_bracket();
9    }
10  }
11
12  /// Broadcast a close bracket to all output streams.
13  fn broadcast_close(&mut self) {
14    for output in self.outputs_mut() {
15      output.close_bracket();
16    }
17  }
18
19  /// Broadcast a done signal to all output streams.
20  fn broadcast_done(&mut self) {
21    for output in self.outputs_mut() {
22      output.done();
23    }
24  }
25
26  /// Broadcast an error to all output streams.
27  fn broadcast_err(&mut self, err: impl Into<String>) {
28    let err = err.into();
29    for output in self.outputs_mut() {
30      output.error(&err);
31    }
32  }
33
34  /// Get all output streams.
35  fn outputs_mut(&mut self) -> OutputIterator<'_>;
36}
37
38/// Trait implemented for output sets with a single output port.
39pub trait SingleOutput: Broadcast {
40  /// The single output port.
41  fn single_output(&mut self) -> &mut dyn Port;
42}
43
44impl<T: Port> Broadcast for T {
45  fn outputs_mut(&mut self) -> OutputIterator<'_> {
46    OutputIterator::new(vec![self])
47  }
48}