Crate streamson_lib[][src]

This library is able to process large JSON data.

It can have various matchers which matches the path (see matcher)

And various handlers to do something with found data (see handlers)

Examples

use streamson_lib::{handler::{self, Handler}, matcher, strategy::{self, Strategy}};
use std::{io, fs, sync::{Arc, Mutex}};

let stdout_handler = Arc::new(Mutex::new(handler::Output::new(io::stdout())));

let file = fs::File::create("out.txt").unwrap();
let handler = handler::Group::new()
    .add_handler(Arc::new(Mutex::new(handler::Output::new(file))))
    .add_handler(stdout_handler.clone());

let first_matcher = matcher::Simple::new(r#"{"users"}[]"#).unwrap();
let second_matcher = matcher::Simple::new(r#"{"groups"}[]"#).unwrap();

let mut trigger = strategy::Trigger::new();

// exports users to stdout and out.txt
trigger.add_matcher(
    Box::new(first_matcher),
    Arc::new(Mutex::new(handler.clone())),
);

// groups are going to be expoted only to stdout
trigger.add_matcher(
    Box::new(second_matcher),
    stdout_handler,
);

for input in vec![
    br#"{"users": [1,2]"#.to_vec(),
    br#", "groups": [3, 4]}"#.to_vec(),
] {
    trigger.process(&input).unwrap();
}
use streamson_lib::{handler::{self, Handler}, matcher, strategy::{Strategy, self}};
use std::{fs, io, sync::{Arc, Mutex}};

let file = fs::File::create("out.txt").unwrap();
let file_handler = Arc::new(
    Mutex::new(handler::Output::new(file))
);
let stdout_handler = Arc::new(Mutex::new(handler::Output::new(io::stdout())));
let handler = handler::Group::new()
    .add_handler(stdout_handler)
    .add_handler(file_handler);

let first_matcher = matcher::Depth::new(1, Some(2));
let second_matcher = matcher::Simple::new(r#"{"users"}[]"#).unwrap();
let matcher = matcher::Combinator::new(first_matcher) |
    matcher::Combinator::new(second_matcher);

let mut trigger = strategy::Trigger::new();

// Paths with depths 1, 2 are exported to out.txt
trigger.add_matcher(
    Box::new(matcher),
    Arc::new(Mutex::new(handler)),
);

for input in vec![
    br#"{"users": [1,2]"#.to_vec(),
    br#", "groups": [3, 4]}"#.to_vec(),
] {
    trigger.process(&input).unwrap();
}
use streamson_lib::{handler::{self, Handler}, matcher, strategy::{Strategy, self}};
use std::{io, fs, sync::{Arc, Mutex}};

let file = fs::File::create("out.txt").unwrap();
let file_handler = Arc::new(
    Mutex::new(handler::Output::new(file))
);
let stdout_handler = Arc::new(Mutex::new(handler::Output::new(io::stdout())));
let handler = handler::Group::new()
    .add_handler(stdout_handler)
    .add_handler(file_handler);

let matcher = matcher::Depth::new(1, Some(2));

let mut trigger = strategy::Trigger::new();

// Paths with depths 1, 2 are exported to out.txt
trigger.add_matcher(
    Box::new(matcher),
    Arc::new(Mutex::new(handler)),
);

for input in vec![
    br#"{"users": [1,2]"#.to_vec(),
    br#", "groups": [3, 4]}"#.to_vec(),
] {
    trigger.process(&input).unwrap();
}

Re-exports

pub use handler::Handler;
pub use path::Path;
pub use streamer::Streamer;
pub use streamer::Token;

Modules

error

Module containing errors

handler

Collections of handler (what to do with matched paths and data).

matcher

Collections of path matchers (matches the path).

path

Structs to handle abstraction over a path in JSON

strategy

Collection of json processing strategies

streamer

Streams significant point of JSON from input data