Struct zenoh_flow_nodes::OutputBuilder
source · pub struct OutputBuilder { /* private fields */ }Expand description
An Output builder is the intermediate structure to obtain either a typed Output<T> or an OutputRaw.
The main difference between both is the type of data they accept: an Output accepts anything that is Into<T>
while an OutputRaw accepts a LinkMessage or anything that is Into<Payload>.
§Planned evolution
Zenoh-Flow will allow tweaking the behaviour of the underlying channels. For now, the senders channels are
unbounded and do not implement a dropping policy, which could lead to issues.
Implementations§
source§impl OutputBuilder
impl OutputBuilder
sourcepub fn raw(self) -> OutputRaw
pub fn raw(self) -> OutputRaw
Consume this OutputBuilder to produce an OutputRaw.
An OutputRaw sends LinkMessages (through forward) or anything that is Into<Payload> (through send and
try_send) to downstream nodes.
The OutputRaw was designed for use cases such as load-balancing or rate-limiting. In this scenarios, the node does not need to access the underlying data and the message can simply be forwarded downstream.
§OutputRaw vs Output<T>
If the node produces instances of T as a result of computations, an Output should be favoured as it sends
anything that is Into<T>. Thus, contrary to an OutputRaw, there is no need to encapsulate T inside a
Payload.
§Example
let output_raw = outputs
.take("test")
.expect("No key named 'test' found")
.raw();sourcepub fn typed<T: Send + Sync + 'static>(
self,
serializer: impl Fn(&mut Vec<u8>, &T) -> Result<()> + Send + Sync + 'static
) -> Output<T>
pub fn typed<T: Send + Sync + 'static>( self, serializer: impl Fn(&mut Vec<u8>, &T) -> Result<()> + Send + Sync + 'static ) -> Output<T>
Consume this OutputBuilder to produce an Output<T>.
An Output<T> sends anything that is Into<T> (through send and try_send) to downstream nodes.
An Output<T> requires knowing how to serialise T. Data is only serialised when it is (a) transmitted
to a node located on another process or (b) transmitted to a node written in a programming language other than
Rust.
The serialisation will automatically be performed by Zenoh-Flow and only when needed.
§Output<T> vs OutputRaw
If the node does not process any data and only has access to a LinkMessage, an OutputRaw would be better
suited as it does not require to downcast it into an object that implements Into<T>.
§Example
let output: Output<u64> = outputs
.take("test")
.expect("No key named 'test' found")
.typed(|buffer: &mut Vec<u8>, data: &u64| {
serde_json::to_writer(buffer, data).map_err(|e| anyhow!(e))
});