From 40424e283c985a927d602fc932ac9852f9d9c4cb Mon Sep 17 00:00:00 2001 From: Chris Wong <lambda.fairy@gmail.com> Date: Sat, 17 Jan 2015 20:52:09 +1300 Subject: [PATCH] Use the Escaper struct directly It's internal anyway, so meh --- maud/src/lib.rs | 14 ++++---------- maud_macros/src/render.rs | 4 +++- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/maud/src/lib.rs b/maud/src/lib.rs index 1bd5f66..446d5de 100644 --- a/maud/src/lib.rs +++ b/maud/src/lib.rs @@ -7,8 +7,9 @@ use std::io::{IoError, IoErrorKind, IoResult}; /// Escape an HTML value. pub fn escape(s: &str) -> String { + use std::fmt::Writer; let mut buf = String::new(); - rt::escape(&mut buf, |w| w.write_str(s)).unwrap(); + rt::Escaper { inner: &mut buf }.write_str(s).unwrap(); buf } @@ -71,8 +72,8 @@ pub mod rt { write!(w, "{}", value) } - struct Escaper<'a, 'b: 'a> { - inner: &'a mut (fmt::Writer + 'b), + pub struct Escaper<'a, 'b: 'a> { + pub inner: &'a mut (fmt::Writer + 'b), } impl<'a, 'b> fmt::Writer for Escaper<'a, 'b> { @@ -90,11 +91,4 @@ pub mod rt { Ok(()) } } - - #[inline] - pub fn escape<F>(w: &mut fmt::Writer, f: F) -> fmt::Result where - F: FnOnce(&mut fmt::Writer) -> fmt::Result - { - f(&mut Escaper { inner: w }) - } } diff --git a/maud_macros/src/render.rs b/maud_macros/src/render.rs index c0bfeb3..0422fb0 100644 --- a/maud_macros/src/render.rs +++ b/maud_macros/src/render.rs @@ -71,7 +71,9 @@ impl<'cx, 's, 'o> Renderer<'cx, 's, 'o> { quote_expr!(self.cx, ::maud::rt::write_fmt($w, $expr)), Escape::Escape => quote_expr!(self.cx, - ::maud::rt::escape($w, |w| ::maud::rt::write_fmt(w, $expr))), + ::maud::rt::write_fmt( + &mut ::maud::rt::Escaper { inner: $w }, + $expr)), }; self.push(expr); }