Put specialized impls in a logical order ()

Follow-up to 

cc @berwyn
This commit is contained in:
Chris Wong 2020-08-07 21:24:00 +10:00 committed by GitHub
parent f85e7b500b
commit a495522259
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -76,16 +76,17 @@ pub trait Render {
}
}
#[cfg(feature = "unstable")]
#[cfg(not(feature = "unstable"))]
impl<T: fmt::Display + ?Sized> Render for T {
default fn render_to(&self, w: &mut String) {
fn render_to(&self, w: &mut String) {
let _ = write!(Escaper::new(w), "{}", self);
}
}
impl<T: AsRef<str>> Render for PreEscaped<T> {
fn render_to(&self, w: &mut String) {
w.push_str(self.0.as_ref());
#[cfg(feature = "unstable")]
impl<T: fmt::Display + ?Sized> Render for T {
default fn render_to(&self, w: &mut String) {
let _ = write!(Escaper::new(w), "{}", self);
}
}
@ -103,17 +104,16 @@ impl Render for str {
}
}
#[cfg(not(feature = "unstable"))]
impl<T: fmt::Display + ?Sized> Render for T {
fn render_to(&self, w: &mut String) {
let _ = write!(Escaper::new(w), "{}", self);
}
}
/// A wrapper that renders the inner value without escaping.
#[derive(Debug, Clone, Copy)]
pub struct PreEscaped<T: AsRef<str>>(pub T);
impl<T: AsRef<str>> Render for PreEscaped<T> {
fn render_to(&self, w: &mut String) {
w.push_str(self.0.as_ref());
}
}
/// A block of markup is a string that does not need to be escaped.
///
/// The `html!` macro expands to an expression of this type.