Skip to main content

Splitter

Struct Splitter 

Source
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>
where T: Send + 'static + Clone,

Source

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)
Source

pub fn build_with_replicas( n_replicas: usize, chunk_size: usize, ) -> impl InOut<Vec<T>, Vec<T>>

Creates a new splitter node with ‘n_replicas’ replicas of the same node.

§Arguments
  • n_replicas - Number of replicas.
  • chunk_size - Number of elements for each chunk.

Trait Implementations§

Source§

impl<T: Clone> Clone for Splitter<T>

Source§

fn clone(&self) -> Splitter<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> InOut<Vec<T>, Vec<T>> for Splitter<T>
where T: Send + 'static + Clone,

Source§

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

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

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>>

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

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

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>,

Source§

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.