pub trait Operator: Node + Send + Sync {
    // Required method
    fn new<'async_trait>(
        context: Context,
        configuration: Configuration,
        inputs: Inputs,
        outputs: Outputs
    ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
       where Self: Sized + 'async_trait;
}
Expand description

An Operator is a node performing transformation over the data it receives, outputting the end result to downstream node(s).

An Operator possesses both Input (either typed or raw) and Output (either typed or raw).

A structure implementing the Operator trait typically needs to keep a reference to its Input(s) and Output(s).

§Example

use async_trait::async_trait;
use zenoh_flow_nodes::prelude::*;

// Use our provided macro to expose the symbol that Zenoh-Flow will look for when it will load
// the shared library.
#[export_operator]
struct NoOp {
    input: Input<usize>,
    output: Output<usize>,
}

#[async_trait]
impl Operator for NoOp {
    async fn new(
        _context: Context,
        _configuration: Configuration,
        mut inputs: Inputs,
        mut outputs: Outputs,
    ) -> Result<Self> {
        Ok(NoOp {
            input: inputs
                .take("in")
                .expect("No input called 'in' found")
                .typed(|bytes| todo!("Provide your deserialiser here")),
            output: outputs
                .take("out")
                .expect("No output called 'out' found")
                .typed(|buffer, data| todo!("Provide your serialiser here")),
        })
    }
}

#[async_trait]
impl Node for NoOp {
    async fn iteration(&self) -> Result<()> {
        let (message, _timestamp) = self.input.recv().await?;
        self.output.send(*message, None).await
    }
}

Required Methods§

source

fn new<'async_trait>( context: Context, configuration: Configuration, inputs: Inputs, outputs: Outputs ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where Self: Sized + 'async_trait,

For a Context, a Configuration, a set of Inputs and Outputs, produce a new Operator.

Operators are at the heart of a data flow, they carry out computations on the data they receive before sending them out to the next downstream node.

Implementors§