diff --git a/examples/custom_handler.rs b/examples/custom.rs similarity index 91% rename from examples/custom_handler.rs rename to examples/custom.rs index 2d1959e..1ae53d2 100644 --- a/examples/custom_handler.rs +++ b/examples/custom.rs @@ -29,9 +29,9 @@ impl From for MyError { } } -struct CustomHtmlHandler; +struct MyHtmlHandler; -impl HtmlHandler for CustomHtmlHandler { +impl HtmlHandler for MyHtmlHandler { fn start(&mut self, mut w: W, container: Container<'_>) -> Result<(), MyError> { let mut default_handler = DefaultHtmlHandler; match container { @@ -62,7 +62,7 @@ fn main() -> Result<(), MyError> { let contents = String::from_utf8(fs::read(&args[1])?)?; let mut writer = Vec::new(); - Org::parse(&contents).html(&mut writer, CustomHtmlHandler)?; + Org::parse(&contents).html(&mut writer, MyHtmlHandler)?; println!("{}", String::from_utf8(writer)?); } diff --git a/examples/iter.rs b/examples/iter.rs new file mode 100644 index 0000000..1f95f67 --- /dev/null +++ b/examples/iter.rs @@ -0,0 +1,19 @@ +use orgize::Org; +use std::env::args; +use std::fs; +use std::io::Result; + +fn main() -> Result<()> { + let args: Vec<_> = args().collect(); + + if args.len() < 2 { + eprintln!("Usage: {} ", args[0]); + } else { + let contents = String::from_utf8(fs::read(&args[1])?).unwrap(); + + for event in Org::parse(&contents).iter() { + println!("{:?}", event); + } + } + Ok(()) +}