[][src]Struct streamson_lib::collector::Collector

pub struct Collector { /* fields omitted */ }

Processes data from input and triggers handlers

Implementations

impl Collector[src]

pub fn new() -> Self[src]

Creates new collector

pub fn add_matcher(
    &mut self,
    matcher: Box<dyn MatchMaker>,
    handlers: &[Arc<Mutex<dyn Handler>>]
)
[src]

Returns a Collector with extended matcher and handlers

Arguments

  • matcher - matcher which matches the path
  • handlers - list of handlers to be triggers when path matches

Example

use streamson_lib::{Collector, matcher, handler};
use std::sync::{Arc, Mutex};

let mut collector = Collector::new();
let handler = handler::PrintLn::new();
let matcher = matcher::Simple::new(r#"{"list"}[]"#).unwrap();
let mut collector = Collector::new();
collector.add_matcher(
    Box::new(matcher),
    &[Arc::new(Mutex::new(handler))]
);

pub fn process(&mut self, input: &[u8]) -> Result<bool, General>[src]

Processes input data

Arguments

  • input - input data

Returns

  • Ok(true) - All data successfully processed
  • Ok(false) - Data were processed, but another input is required
  • Err(_) - error occured during processing

Example

use streamson_lib::Collector;

let mut collector = Collector::new();
collector.process(br#"{}"#);

Errors

If parsing logic finds that JSON is not valid, it returns error::General.

Note that streamson assumes that its input is a valid JSONs and if not. It still might be splitted without an error. This is caused because streamson does not validate JSON.

Trait Implementations

impl Default for Collector[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.