Add a dump_events example to aid debugging.
This commit is contained in:
parent
d77db591bc
commit
df4d520878
1 changed files with 38 additions and 0 deletions
38
saphyr/examples/dump_events.rs
Normal file
38
saphyr/examples/dump_events.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
extern crate yaml_rust;
|
||||
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::prelude::*;
|
||||
use yaml_rust::{
|
||||
parser::{MarkedEventReceiver, Parser},
|
||||
scanner::Marker,
|
||||
Event,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct EventSink {
|
||||
events: Vec<(Event, Marker)>,
|
||||
}
|
||||
|
||||
impl MarkedEventReceiver for EventSink {
|
||||
fn on_event(&mut self, ev: Event, mark: Marker) {
|
||||
self.events.push((ev, mark));
|
||||
}
|
||||
}
|
||||
|
||||
fn str_to_events(yaml: &str) -> Vec<(Event, Marker)> {
|
||||
let mut sink = EventSink { events: Vec::new() };
|
||||
let mut parser = Parser::new(yaml.chars());
|
||||
// Load events using our sink as the receiver.
|
||||
parser.load(&mut sink, true).unwrap();
|
||||
sink.events
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let args: Vec<_> = env::args().collect();
|
||||
let mut f = File::open(&args[1]).unwrap();
|
||||
let mut s = String::new();
|
||||
f.read_to_string(&mut s).unwrap();
|
||||
|
||||
dbg!(str_to_events(&s));
|
||||
}
|
Loading…
Reference in a new issue