diff --git a/src/template_utils.rs b/src/template_utils.rs index 08edd96..0fa01f2 100644 --- a/src/template_utils.rs +++ b/src/template_utils.rs @@ -6,7 +6,7 @@ /// formats the value using Display and then html-encodes the result. pub trait ToHtml { /// Write self to `out`, which is in html representation. - fn to_html(&self, out: &mut dyn Write) -> io::Result<()>; + fn to_html(&self, out: &mut W) -> io::Result<()> where W: ?Sized, for<'a> &'a mut W: Write; } /// Wrapper object for data that should be outputted as raw html @@ -16,21 +16,21 @@ pub struct Html(pub T); impl ToHtml for Html { #[inline] - fn to_html(&self, out: &mut dyn Write) -> io::Result<()> { + fn to_html(&self, mut out: &mut W) -> io::Result<()> where W: ?Sized, for<'a> &'a mut W: Write { write!(out, "{}", self.0) } } impl ToHtml for T { #[inline] - fn to_html(&self, out: &mut dyn Write) -> io::Result<()> { + fn to_html(&self, out: &mut W) -> io::Result<()> where W: ?Sized, for<'a> &'a mut W: Write { write!(ToHtmlEscapingWriter(out), "{}", self) } } -struct ToHtmlEscapingWriter<'a>(&'a mut dyn Write); +struct ToHtmlEscapingWriter<'w, W: ?Sized>(&'w mut W); -impl<'a> Write for ToHtmlEscapingWriter<'a> { +impl<'w, W> Write for ToHtmlEscapingWriter<'w, W> where W: ?Sized, for<'a> &'a mut W: Write { #[inline] // This takes advantage of the fact that `write` doesn't have to write everything, // and the call will be retried with the rest of the data @@ -56,10 +56,10 @@ impl<'a> Write for ToHtmlEscapingWriter<'a> { } } -impl<'a> ToHtmlEscapingWriter<'a> { +impl<'w, W> ToHtmlEscapingWriter<'w, W> where W: ?Sized, for<'a> &'a mut W: Write { #[inline(never)] fn write_one_byte_escaped( - out: &mut impl Write, + mut out: &mut W, data: &[u8], ) -> io::Result { let next = data.get(0);