pub struct Splitter<T> { /* private fields */ }Expand description
Splitter.
This node receives a vector, split it into chunks of size chunk_size
and send each chunk to the next node.
Implementations§
Source§impl<T> Splitter<T>
impl<T> Splitter<T>
Sourcepub fn build(chunk_size: usize) -> impl InOut<Vec<T>, Vec<T>>
pub fn build(chunk_size: usize) -> impl InOut<Vec<T>, Vec<T>>
Creates a new splitter node.
§Arguments
chunk_size- Number of elements for each chunk.
§Examples
Given a stream of numbers, we create a pipeline with a splitter that create vectors of two elements each.
use ppl::{prelude::*, templates::misc::{SourceIter, Splitter, SinkVec, Aggregator}};
let vec = vec![1, 2, 3, 4, 5, 6, 7, 8];
let p = pipeline![
SourceIter::build(vec.into_iter()),
Aggregator::build(8), // We aggregate each element in a vector.
Splitter::build(2), // We split the received vector in 4 sub-vector of size 2.
SinkVec::build()
];
let mut res = p.start_and_wait_end().unwrap();
assert_eq!(res.len(), 4)Trait Implementations§
Source§impl<T> InOut<Vec<T>, Vec<T>> for Splitter<T>
impl<T> InOut<Vec<T>, Vec<T>> for Splitter<T>
Source§fn run(&mut self, input: Vec<T>) -> Option<Vec<T>>
fn run(&mut self, input: Vec<T>) -> Option<Vec<T>>
This method is called each time the node receive an input.
Source§fn 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.
Source§fn 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.
Source§fn produce(&mut self) -> Option<Vec<T>>
fn produce(&mut self) -> Option<Vec<T>>
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.Source§fn 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.
Auto Trait Implementations§
impl<T> Freeze for Splitter<T>
impl<T> RefUnwindSafe for Splitter<T>where
T: RefUnwindSafe,
impl<T> Send for Splitter<T>where
T: Send,
impl<T> Sync for Splitter<T>where
T: Sync,
impl<T> Unpin for Splitter<T>where
T: Unpin,
impl<T> UnsafeUnpin for Splitter<T>
impl<T> UnwindSafe for Splitter<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more