pub trait InOut<TIn, TOut>: DynClone {
// Required method
fn run(&mut self, input: TIn) -> Option<TOut>;
// Provided methods
fn produce(&mut self) -> Option<TOut> { ... }
fn number_of_replicas(&self) -> usize { ... }
fn is_ordered(&self) -> bool { ... }
fn is_producer(&self) -> bool { ... }
}
Expand description
Trait defining a node that receive an input and produce an output.
§Examples:
A node that receive an integer and increment it by one:
use ppl::prelude::*;
#[derive(Clone)]
struct Worker {}
impl InOut<i32, i32> for Worker {
fn run(&mut self, input: i32) -> Option<i32> {
Some(input + 1)
}
}
Required Methods§
Provided Methods§
sourcefn produce(&mut self) -> Option<TOut>
fn produce(&mut self) -> Option<TOut>
If is_producer
is true
then this method will be called by the rts immediately
after the execution of run
.
This method is called by the rts until a None is returned.
When None is returned, the node will return to wait for another input.
This method can be useful when we have a node that produce multiple outputs for each input it receive.
sourcefn number_of_replicas(&self) -> usize
fn number_of_replicas(&self) -> usize
This method return the number of replicas of the node. Override this method allow to choose the number of replicas of the node.
sourcefn is_ordered(&self) -> bool
fn is_ordered(&self) -> bool
This method return a boolean that represent if the node produce the output in an ordered way or not. Override this method allow choosing if the node must produce the output preserving the order of the input.
sourcefn is_producer(&self) -> bool
fn is_producer(&self) -> bool
This method return a boolean that represent if the node is a producer or not. Override this method allow choosing if the node produce multiple output for each input received, or not.