Skip to content

Commit d5c65ab

Browse files
Merge pull request askama-rs#199 from Kijewski/pr-dyn-compat
"object safe" is now "dyn-compatible"
2 parents 206231b + a4527b8 commit d5c65ab

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

rinja/src/lib.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,11 @@ impl<T: Template + ?Sized> Template for &T {
180180
const SIZE_HINT: usize = T::SIZE_HINT;
181181
}
182182

183-
/// Object-safe wrapper trait around [`Template`] implementers
183+
/// [`dyn`-compatible] wrapper trait around [`Template`] implementers
184184
///
185-
/// This trades reduced performance (mostly due to writing into `dyn Write`) for object safety.
185+
/// This trades reduced performance (mostly due to writing into `dyn Write`) for dyn-compatibility.
186+
///
187+
/// [`dyn`-compatible]: https://doc.rust-lang.org/stable/reference/items/traits.html#dyn-compatibility
186188
pub trait DynTemplate {
187189
/// Helper method which allocates a new `String` and renders into it
188190
#[cfg(feature = "alloc")]
@@ -200,11 +202,13 @@ pub trait DynTemplate {
200202
}
201203

202204
impl<T: Template> DynTemplate for T {
205+
#[inline]
203206
#[cfg(feature = "alloc")]
204207
fn dyn_render(&self) -> Result<String> {
205208
<Self as Template>::render(self)
206209
}
207210

211+
#[inline]
208212
fn dyn_render_into(&self, writer: &mut dyn fmt::Write) -> Result<()> {
209213
<Self as Template>::render_into(self, writer)
210214
}
@@ -215,12 +219,14 @@ impl<T: Template> DynTemplate for T {
215219
<Self as Template>::write_into(self, writer)
216220
}
217221

222+
#[inline]
218223
fn size_hint(&self) -> usize {
219-
Self::SIZE_HINT
224+
<Self as Template>::SIZE_HINT
220225
}
221226
}
222227

223228
impl fmt::Display for dyn DynTemplate {
229+
#[inline]
224230
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
225231
self.dyn_render_into(f).map_err(|_| fmt::Error {})
226232
}

0 commit comments

Comments
 (0)