pub struct Extractor { /* private fields */ }Expand description
This struct uses streamson_lib::matcher to decode data.
§Examples
use std::io;
use streamson_lib::{error, matcher};
use streamson_tokio::decoder::Extractor;
use tokio::{fs, stream::StreamExt};
use tokio_util::codec::FramedRead;
async fn process() -> Result<(), error::General> {
let mut file = fs::File::open("/tmp/large.json").await?;
let matcher = matcher::Combinator::new(matcher::Simple::new(r#"{"users"}[]"#).unwrap())
| matcher::Combinator::new(matcher::Simple::new(r#"{"groups"}[]"#).unwrap());
let extractor = Extractor::new(matcher, true);
let mut output = FramedRead::new(file, extractor);
while let Some(item) = output.next().await {
let (path, data) = item?;
// Do something with extracted data
}
Ok(())
}Implementations§
Trait Implementations§
Source§impl Decoder for Extractor
impl Decoder for Extractor
Source§fn decode(
&mut self,
buf: &mut BytesMut,
) -> Result<Option<Self::Item>, Self::Error>
fn decode( &mut self, buf: &mut BytesMut, ) -> Result<Option<Self::Item>, Self::Error>
Attempts to decode a frame from the provided buffer of bytes. Read more
Auto Trait Implementations§
impl Freeze for Extractor
impl !RefUnwindSafe for Extractor
impl Send for Extractor
impl !Sync for Extractor
impl Unpin for Extractor
impl !UnwindSafe for Extractor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more