summaryrefslogtreecommitdiffstats
path: root/crates/core/thin_edge_json/examples/validate.rs
blob: cbab5138a76ac71c8c0621b71a26c5ebe8a1fc04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use std::env;
use thin_edge_json::measurement::MeasurementVisitor;
use time::OffsetDateTime;

#[global_allocator]
static GLOBAL: &stats_alloc::StatsAlloc<std::alloc::System> = &stats_alloc::INSTRUMENTED_SYSTEM;

fn main() -> anyhow::Result<()> {
    let region = stats_alloc::Region::new(GLOBAL);

    let mut args = env::args();
    let _ = args.next();
    let input_file = args.next().expect("input: file name");

    let input = std::fs::read_to_string(input_file)?;

    let mut builder = DummyVisitor;

    let res: anyhow::Result<()> =
        thin_edge_json::parser::parse_str(&input, &mut builder).map_err(Into::into);

    if res.is_ok() {
        println!("OK");
    }

    println!("{:?}", region.change());

    res
}

#[derive(thiserror::Error, Debug)]
enum DummyError {}

struct DummyVisitor;

impl MeasurementVisitor for DummyVisitor {
    type Error = DummyError;

    fn visit_timestamp(&mut self, _value: OffsetDateTime) -> Result<(), Self::Error> {
        Ok(())
    }
    fn visit_measurement(&mut self, _name: &str, _value: f64) -> Result<(), Self::Error> {
        Ok(())
    }
    fn visit_start_group(&mut self, _group: &str) -> Result<(), Self::Error> {
        Ok(())
    }
    fn visit_end_group(&mut self) -> Result<(), Self::Error> {
        Ok(())
    }
}