[−][src]Struct streamson_lib::strategy::convert::Convert
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>,
convert_function: Box<dyn Fn(&Path, &[u8]) -> Vec<u8>>
)[src]
&mut self,
matcher: Box<dyn MatchMaker>,
convert_function: Box<dyn Fn(&Path, &[u8]) -> Vec<u8>>
)
Adds a mathcher and a handler to Convert
Arguments
matcher- matcher which matches the pathconvert_function- funtions which performs the conversion
Example
use streamson_lib::{strategy, matcher, handler}; let mut convert = strategy::Convert::new(); let matcher = matcher::Simple::new(r#"{"list"}[]"#).unwrap(); convert.add_matcher( Box::new(matcher), Box::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, matcher}; let mut convert = strategy::Convert::new(); let matcher = matcher::Simple::new(r#"{"password"}"#).unwrap(); convert.add_matcher( Box::new(matcher), Box::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
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,