Skip to content

Commit

Permalink
Restrict PreEscaped to T: AsRef<str>
Browse files Browse the repository at this point in the history
Closes #54
  • Loading branch information
lambda-fairy committed Oct 22, 2016
1 parent 9ff5ff4 commit 90e0f1c
Showing 1 changed file with 3 additions and 15 deletions.
18 changes: 3 additions & 15 deletions maud/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,11 @@ impl<'a, T: Render + ?Sized> RenderOnce for &'a T {

/// A wrapper that renders the inner value without escaping.
#[derive(Debug)]
pub struct PreEscaped<T>(pub T);
pub struct PreEscaped<T: AsRef<str>>(pub T);

impl<T: fmt::Display> Render for PreEscaped<T> {
default fn render_to(&self, w: &mut String) {
let _ = write!(w, "{}", self.0);
}
}

impl Render for PreEscaped<String> {
fn render_to(&self, w: &mut String) {
w.push_str(&self.0);
}
}

impl<'a> Render for PreEscaped<&'a str> {
impl<T: AsRef<str>> Render for PreEscaped<T> {
fn render_to(&self, w: &mut String) {
w.push_str(self.0);
w.push_str(self.0.as_ref());
}
}

Expand Down

0 comments on commit 90e0f1c

Please sign in to comment.