[−][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>,
handlers: Vec<Arc<Mutex<dyn Handler>>>
)
[src]
&mut self,
matcher: Box<dyn MatchMaker>,
handlers: Vec<Arc<Mutex<dyn Handler>>>
)
Adds a mathcher and a handler to Convert
Arguments
matcher
- matcher which matches the pathhandlers
- 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
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,
pub 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.
pub 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>,