Struct zenoh_flow_nodes::InputBuilder
source · pub struct InputBuilder { /* private fields */ }Expand description
An InputBuilder is the intermediate structure to obtain either an Input<T> or an InputRaw.
The main difference between both is the type of data they expose: an Input<T> automatically
tries to downcast or deserialize the data contained in the message to expose &T, while an
InputRaw simply exposes a LinkMessage.
§Planned evolution
Zenoh-Flow will allow tweaking the behaviour of the underlying channels. For now, the
receivers channels are unbounded and do not implement a dropping policy, which could lead to
issues.
Implementations§
source§impl InputBuilder
impl InputBuilder
sourcepub fn raw(self) -> InputRaw
pub fn raw(self) -> InputRaw
Consume the InputBuilder to produce an InputRaw.
An InputRaw exposes the LinkMessage it receives, without trying to perform any conversion on the data.
The InputRaw was designed for use cases such as load-balancing or rate-limiting. In these scenarios, the node does not need to access the underlying data.
§InputRaw vs Input<T>
If the node needs access to the data to perform computations, an Input<T> should be
favoured as it performs the conversion automatically.
§Example
let input_raw = inputs.take("test raw")
.expect("No input name 'test raw' found")
.raw();sourcepub fn typed<T>(
self,
deserializer: impl Fn(&[u8]) -> Result<T> + Send + Sync + 'static
) -> Input<T>
pub fn typed<T>( self, deserializer: impl Fn(&[u8]) -> Result<T> + Send + Sync + 'static ) -> Input<T>
Consume the InputBuilder to produce an Input<T>.
An Input<T> tries to automatically convert the data contained in the LinkMessage in
order to expose &T. Depending on if the data is received serialised or not, to perform
this conversion either the deserialiser is called or a downcast is attempted.
§Input<T> vs InputRaw
If the node does need to access the data contained in the LinkMessage, an InputRaw should be favoured as it does not try to perform the extra conversion steps.
§Example
let input: Input<u64> = inputs.take("test typed")
.expect("No input name 'test typed' found")
.typed(
|bytes| serde_json::from_slice(bytes).map_err(|e| anyhow!(e))
);