Trait zenoh_flow_nodes::prelude::Sink
source · pub trait Sink: Node + Send + Sync {
// Required method
fn new<'async_trait>(
context: Context,
configuration: Configuration,
inputs: Inputs
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>
where Self: Sized + 'async_trait;
}Expand description
A Sink exposes the outcome of the data flow processing.
A Sink only possesses Input (either typed or raw) as its
purpose is to communicate with entities outside of the data flow.
A structure implementing the Sink trait typically needs to keep a reference to its Input(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_sink]
struct GenericSink {
input: Input<usize>,
}
#[async_trait]
impl Sink for GenericSink {
async fn new(
_context: Context,
_configuration: Configuration,
mut inputs: Inputs,
) -> Result<Self> {
let input = inputs
.take("in")
.expect("No input called 'in' found")
.typed(|bytes| todo!("Provide your deserializer here"));
Ok(GenericSink { input })
}
}
#[async_trait]
impl Node for GenericSink {
async fn iteration(&self) -> Result<()> {
let (message, _timestamp) = self.input.recv().await?;
println!("{}", *message);
Ok(())
}
}Required Methods§
sourcefn new<'async_trait>(
context: Context,
configuration: Configuration,
inputs: Inputs
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: Sized + 'async_trait,
fn new<'async_trait>(
context: Context,
configuration: Configuration,
inputs: Inputs
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: Sized + 'async_trait,
For a Context, a Configuration and Inputs, produce a new Sink.
Sinks only possess Inputs, their objective is to send the result of the computations to the external world.