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

source

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();
source

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))
    });

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsNode<T> for T

source§

fn as_node(&self) -> &T

source§

impl<T> AsNodeMut<T> for T

source§

fn as_node_mut(&mut self) -> &mut T

source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> SendSyncAny for T
where T: 'static + Send + Sync,

source§

fn as_any(&self) -> &(dyn Any + 'static)

source§

fn as_mut_any(&mut self) -> &mut (dyn Any + 'static)

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more