diff --git a/README.md b/README.md index d789456..2885b8a 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ use std::convert::From; use std::io::{Error as IOError, Write}; use std::string::FromUtf8Error; -use orgize::export::{html::Escape, DefaultHtmlHandler, HtmlHandler}; +use orgize::export::{DefaultHtmlHandler, HtmlHandler}; use orgize::{Element, Org}; use slugify::slugify; @@ -103,6 +103,7 @@ impl From for MyError { } } +#[derive(Default)] struct MyHtmlHandler(DefaultHtmlHandler); impl HtmlHandler for MyHtmlHandler { @@ -115,7 +116,7 @@ impl HtmlHandler for MyHtmlHandler { w, "", title.level, - slugify!(title.raw), + slugify!(&title.raw), )?; } } else { @@ -137,8 +138,7 @@ impl HtmlHandler for MyHtmlHandler { fn main() -> Result<(), MyError> { let mut writer = Vec::new(); - - let mut handler = MyHtmlHandler(DefaultHtmlHandler); + let mut handler = MyHtmlHandler::default(); Org::parse("* title\n*section*").html_with_handler(&mut writer, &mut handler)?; assert_eq!( diff --git a/orgize/examples/custom.rs b/orgize/examples/custom.rs index 112388c..15ae7e9 100644 --- a/orgize/examples/custom.rs +++ b/orgize/examples/custom.rs @@ -29,6 +29,7 @@ impl From for MyError { } } +#[derive(Default)] struct MyHtmlHandler(DefaultHtmlHandler); impl HtmlHandler for MyHtmlHandler { @@ -70,7 +71,7 @@ fn main() -> Result<(), MyError> { let contents = String::from_utf8(fs::read(&args[1])?)?; let mut writer = Vec::new(); - let mut handler = MyHtmlHandler(DefaultHtmlHandler); + let mut handler = MyHtmlHandler::default(); Org::parse(&contents).html_with_handler(&mut writer, &mut handler)?; println!("{}", String::from_utf8(writer)?); diff --git a/orgize/src/export/html.rs b/orgize/src/export/html.rs index 10975bc..4ed3587 100644 --- a/orgize/src/export/html.rs +++ b/orgize/src/export/html.rs @@ -36,7 +36,7 @@ impl> fmt::Display for Escape { } } -pub trait HtmlHandler> { +pub trait HtmlHandler>: Default { fn start(&mut self, mut w: W, element: &Element) -> Result<(), E> { use Element::*; @@ -199,6 +199,7 @@ pub trait HtmlHandler> { } } +#[derive(Default)] pub struct DefaultHtmlHandler; impl HtmlHandler for DefaultHtmlHandler {} diff --git a/orgize/src/export/org.rs b/orgize/src/export/org.rs index 5ef5c2e..5ac384d 100644 --- a/orgize/src/export/org.rs +++ b/orgize/src/export/org.rs @@ -3,7 +3,7 @@ use std::io::{Error, Write}; use crate::elements::{Element, Timestamp}; use crate::export::write_datetime; -pub trait OrgHandler> { +pub trait OrgHandler>: Default { fn start(&mut self, mut w: W, element: &Element) -> Result<(), E> { use Element::*; @@ -233,6 +233,7 @@ fn write_timestamp(mut w: W, timestamp: &Timestamp) -> std::io::Result Ok(()) } +#[derive(Default)] pub struct DefaultOrgHandler; impl OrgHandler for DefaultOrgHandler {} diff --git a/orgize/src/lib.rs b/orgize/src/lib.rs index ed25fc7..c6fc34c 100644 --- a/orgize/src/lib.rs +++ b/orgize/src/lib.rs @@ -114,6 +114,7 @@ //! } //! } //! +//! #[derive(Default)] //! struct MyHtmlHandler(DefaultHtmlHandler); //! //! impl HtmlHandler for MyHtmlHandler { @@ -148,7 +149,7 @@ //! //! fn main() -> Result<(), MyError> { //! let mut writer = Vec::new(); -//! let mut handler = MyHtmlHandler(DefaultHtmlHandler); +//! let mut handler = MyHtmlHandler::default(); //! Org::parse("* title\n*section*").html_with_handler(&mut writer, &mut handler)?; //! //! assert_eq!(