In

Trait In 

Source
pub trait In<TIn, TCollected>
where TIn: Send,
{ // Required methods fn run(&mut self, input: TIn); fn finalize(self) -> Option<TCollected>; // Provided method fn is_ordered(&self) -> bool { ... } }
Expand description

Trait defining a node that receive data.

§Examples:

A node that increment an internal counter each time an input is received and return the total count of input received:

use ppl::prelude::*;
struct Sink {
counter: usize,
}
impl In<u64, usize> for Sink {
   fn run(&mut self, input: u64) {
       println!("{}", input);
      self.counter = self.counter + 1;
   }

   fn finalize(self) -> Option<usize> {
       println!("End");
      Some(self.counter)
  }
}

Required Methods§

Source

fn run(&mut self, input: TIn)

This method is called each time the node receive an input.

Source

fn finalize(self) -> Option<TCollected>

This method is called before the node terminates. Is useful to take out data at the end of the computation.

Provided Methods§

Source

fn is_ordered(&self) -> bool

This method return a boolean that represent if the node must receive the input respecting the order of arrival. Override this method allow choosing if the node must preserve the order of the input.

Implementors§

Source§

impl<T> In<T, Vec<T>> for OrderedSinkVec<T>
where T: Send + 'static,

Source§

impl<T> In<T, Vec<T>> for SinkVec<T>
where T: Send + 'static,

Source§

impl<TIn, TCollected, F> In<TIn, TCollected> for F
where F: FnMut(TIn) -> TCollected, TIn: Send,