Struct streamson_generator::StreamsonGenerator[][src]

pub struct StreamsonGenerator<G> where
    G: Generator<Yield = Vec<u8>, Return = ()> + Unpin
{ /* fields omitted */ }

Wraps streamson extraction around a generator

Example

#![feature(generators, generator_trait)]

use std::{
    fs,
    io::{self, Read},
    str::FromStr,
    pin::Pin,
    ops::{Generator, GeneratorState},
};
use streamson_generator::StreamsonGenerator;
use streamson_lib::matcher::Simple;

fn process_json() -> io::Result<()> {
    let mut file = fs::File::open("/tmp/large.json")?;
    let mut input_generator = move || {
        loop {
            let mut buffer = vec![0; 2048];
            if file.read(&mut buffer).unwrap() == 0 {
                break;
            }
            yield buffer;
        }
    };

    let matcher = Box::new(Simple::from_str(r#"{"users"}[]{"name"}"#).unwrap());
    let mut output_generator = StreamsonGenerator::new(input_generator, matcher);

    for item in output_generator {
        match item {
            Ok((path, data)) => {
                // Do something with the data
            },
            Err(err) => {
                // Deal with error situation
            }
        }
    }

    Ok(())
}

Implementations

impl<G> StreamsonGenerator<G> where
    G: Generator<Yield = Vec<u8>, Return = ()> + Unpin
[src]

pub fn new(input_generator: G, matcher: Box<dyn Matcher>) -> Self[src]

Trait Implementations

impl<G> Generator<()> for StreamsonGenerator<G> where
    G: Generator<Yield = Vec<u8>, Return = ()> + Unpin
[src]

type Yield = Result<(String, Vec<u8>), StreamsonError>

🔬 This is a nightly-only experimental API. (generator_trait)

The type of value this generator yields. Read more

type Return = ()

🔬 This is a nightly-only experimental API. (generator_trait)

The type of value this generator returns. Read more

impl<G> Iterator for StreamsonGenerator<G> where
    G: Generator<Yield = Vec<u8>, Return = ()> + Unpin
[src]

type Item = Result<(String, Vec<u8>), StreamsonError>

The type of the elements being iterated over.

Auto Trait Implementations

impl<G> RefUnwindSafe for StreamsonGenerator<G> where
    G: RefUnwindSafe

impl<G> Send for StreamsonGenerator<G> where
    G: Send

impl<G> Sync for StreamsonGenerator<G> where
    G: Sync

impl<G> Unpin for StreamsonGenerator<G>

impl<G> UnwindSafe for StreamsonGenerator<G> where
    G: UnwindSafe

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<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

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.