Skip to content

Commit

Permalink
Remove RenderOnce
Browse files Browse the repository at this point in the history
Closes #68
  • Loading branch information
lambda-fairy committed Dec 23, 2016
1 parent 7925fba commit c57ee6e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 50 deletions.
35 changes: 0 additions & 35 deletions maud/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,41 +85,6 @@ impl Render for str {
}
}

/// Represents a type that can be rendered as HTML, where the rendering
/// operation consumes the value.
///
/// See the [`Render`](trait.Render.html) documentation for advice on
/// how to use this trait.
pub trait RenderOnce: Sized {
/// Renders `self` as a block of `Markup`, consuming it in the
/// process.
fn render_once(self) -> Markup {
let mut buffer = String::new();
self.render_once_to(&mut buffer);
PreEscaped(buffer)
}

/// Appends a representation of `self` to the given string,
/// consuming `self` in the process.
///
/// Its default implementation just calls `.render_once()`, but you
/// may override it with something more efficient.
///
/// Note that no further escaping is performed on data written to
/// the buffer. If you override this method, you must make sure that
/// any data written is properly escaped, whether by hand or using
/// the [`Escaper`](struct.Escaper.html) wrapper struct.
fn render_once_to(self, buffer: &mut String) {
buffer.push_str(&self.render_once().into_string());
}
}

impl<'a, T: Render + ?Sized> RenderOnce for &'a T {
fn render_once_to(self, w: &mut String) {
self.render_to(w);
}
}

/// A wrapper that renders the inner value without escaping.
#[derive(Debug)]
pub struct PreEscaped<T: AsRef<str>>(pub T);
Expand Down
5 changes: 4 additions & 1 deletion maud_macros/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ impl<'cx, 'a> Renderer<'cx, 'a> {
/// Appends the result of an expression.
pub fn splice(&mut self, expr: P<Expr>) {
let w = self.writer;
let expr = quote_expr!(self.cx, { use ::maud::RenderOnce; $expr.render_once_to(&mut $w) });
let expr = quote_expr!(self.cx, {
use ::maud::Render as __maud_Render;
$expr.render_to(&mut $w);
});
let stmt = self.wrap_stmt(expr);
self.push(stmt);
}
Expand Down
14 changes: 0 additions & 14 deletions maud_macros/tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,3 @@ fn render_impl() {
assert_eq!(s1, "pinkie");
assert_eq!(s2, "pinkie");
}

#[test]
fn render_once_impl() {
struct Once(String);
impl maud::RenderOnce for Once {
fn render_once_to(self, w: &mut String) {
w.push_str(&self.0);
}
}

let once = Once(String::from("pinkie"));
let s = html!((once)).into_string();
assert_eq!(s, "pinkie");
}

0 comments on commit c57ee6e

Please sign in to comment.