From 8eb655207e0a9fc2707487cede05a3439e5ee871 Mon Sep 17 00:00:00 2001 From: Chris Wong <lambda.fairy@gmail.com> Date: Mon, 26 Jan 2015 12:13:32 +1300 Subject: [PATCH] Take inner closure by value instead of by reference Closes #1 --- maud/src/lib.rs | 10 ++++++---- maud_macros/src/render.rs | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/maud/src/lib.rs b/maud/src/lib.rs index 0ecb57f..5719a04 100644 --- a/maud/src/lib.rs +++ b/maud/src/lib.rs @@ -171,11 +171,11 @@ pub fn escape(s: &str) -> String { /// /// Use `.render()` to convert it to a `String`, or `.render_to()` to /// write it directly to a handle. -pub struct Markup<'a> { - callback: &'a (Fn(&mut fmt::Writer) -> fmt::Result + 'a), +pub struct Markup<F> { + callback: F, } -impl<'a> Markup<'a> { +impl<F> Markup<F> where F: Fn(&mut fmt::Writer) -> fmt::Result { /// Render the markup to a `String`. pub fn render(&self) -> String { let mut buf = String::new(); @@ -218,7 +218,9 @@ pub mod rt { use super::Markup; #[inline] - pub fn make_markup<'a>(f: &'a (Fn(&mut fmt::Writer) -> fmt::Result + 'a)) -> Markup<'a> { + pub fn make_markup<F>(f: F) -> Markup<F> + where F: Fn(&mut fmt::Writer) -> fmt::Result + { Markup { callback: f } } diff --git a/maud_macros/src/render.rs b/maud_macros/src/render.rs index 0422fb0..0def710 100644 --- a/maud_macros/src/render.rs +++ b/maud_macros/src/render.rs @@ -35,7 +35,7 @@ impl<'cx, 's, 'o> Renderer<'cx, 's, 'o> { render.cx }; quote_expr!(cx, - ::maud::rt::make_markup(&|&: $w: &mut ::std::fmt::Writer| -> Result<(), ::std::fmt::Error> { + ::maud::rt::make_markup(|&: $w: &mut ::std::fmt::Writer| -> Result<(), ::std::fmt::Error> { $stmts Ok(()) }))