Remove `impl<T: Display> Render for &T`
This specialization should be discussed more deeply. This specialization is very useful when you want to render the non-specialized types such as url::Url. However, when you write a reference type inside templates, that fallbacks to non-specialized call, which is slower than specialized call.
This commit is contained in:
parent
fd3d224067
commit
e12e42e15a
|
@ -17,28 +17,28 @@ pub trait Render {
|
|||
}
|
||||
}
|
||||
|
||||
/// Autoref-based stable specialization
|
||||
///
|
||||
/// Explanation can be found [here](https://github.com/dtolnay/case-studies/blob/master/autoref-specialization/README.md)
|
||||
impl<T: Display> Render for &T {
|
||||
fn render(&self, b: &mut Buffer) -> fmt::Result {
|
||||
fmt::write(b, format_args!("{}", self))
|
||||
}
|
||||
|
||||
fn render_escaped(&self, b: &mut Buffer) -> fmt::Result {
|
||||
struct Wrapper<'a>(&'a mut Buffer);
|
||||
|
||||
impl<'a> fmt::Write for Wrapper<'a> {
|
||||
#[inline]
|
||||
fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
escape::escape_to_buf(s, self.0);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fmt::write(&mut Wrapper(b), format_args!("{}", self))
|
||||
}
|
||||
}
|
||||
// /// Autoref-based stable specialization
|
||||
// ///
|
||||
// /// Explanation can be found [here](https://github.com/dtolnay/case-studies/blob/master/autoref-specialization/README.md)
|
||||
// impl<T: Display> Render for &T {
|
||||
// fn render(&self, b: &mut Buffer) -> fmt::Result {
|
||||
// fmt::write(b, format_args!("{}", self))
|
||||
// }
|
||||
//
|
||||
// fn render_escaped(&self, b: &mut Buffer) -> fmt::Result {
|
||||
// struct Wrapper<'a>(&'a mut Buffer);
|
||||
//
|
||||
// impl<'a> fmt::Write for Wrapper<'a> {
|
||||
// #[inline]
|
||||
// fn write_str(&mut self, s: &str) -> fmt::Result {
|
||||
// escape::escape_to_buf(s, self.0);
|
||||
// Ok(())
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// fmt::write(&mut Wrapper(b), format_args!("{}", self))
|
||||
// }
|
||||
// }
|
||||
|
||||
impl Render for str {
|
||||
#[inline]
|
||||
|
|
Loading…
Reference in New Issue