[][src]Struct streamson_lib::strategy::convert::Convert

pub struct Convert { /* fields omitted */ }

Processes data from input and triggers handlers

Implementations

impl Convert[src]

pub fn new() -> Self[src]

Creates a new Convert

It should replace a parts of the JSON using custom bytes data are read.

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

Adds a mathcher and a handler to Convert

Arguments

  • matcher - matcher which matches the path
  • handlers - funtions which should be run to convert the data

Example

use streamson_lib::{strategy, matcher, handler, path::Path};
use std::sync::{Arc, Mutex};

let mut convert = strategy::Convert::new();

let matcher = matcher::Simple::new(r#"{"list"}[]"#).unwrap();
convert.add_matcher(
    Box::new(matcher),
    vec![Arc::new(Mutex::new(handler::Replace::new(vec![b'"', b'*', b'*', b'*', b'"'])))],
);

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

Processes input data

Arguments

  • input - input data

Returns

  • `Ok(_) processing passed, more data might be needed
  • Err(_) when input is not correct json

Example

use streamson_lib::{strategy, handler, matcher, path::Path};
use std::sync::{Arc, Mutex};

let mut convert = strategy::Convert::new();
let matcher = matcher::Simple::new(r#"{"password"}"#).unwrap();
convert.add_matcher(
    Box::new(matcher),
    vec![Arc::new(Mutex::new(handler::Replace::new(vec![b'"', b'*', b'*', b'*', b'"'])))],
);

let data = convert.process(br#"{"password": "secret"}"#).unwrap();
for part in data {
    // Do something with converted data
}

Errors

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

Trait Implementations

impl Default for Convert[src]

Auto Trait Implementations

impl !RefUnwindSafe for Convert

impl Send for Convert

impl !Sync for Convert

impl Unpin for Convert

impl !UnwindSafe for Convert

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.