From 23f0e88b6cb6e31ba623b46a9ffa0c5c65d25711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Sat, 12 Oct 2024 16:54:48 +0200 Subject: [PATCH 1/2] "object safe" is now "dyn-compatible" The phrase was changed in . --- rinja/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rinja/src/lib.rs b/rinja/src/lib.rs index e528d5e39..c30744f9a 100644 --- a/rinja/src/lib.rs +++ b/rinja/src/lib.rs @@ -175,9 +175,11 @@ impl Template for &T { const MIME_TYPE: &'static str = T::MIME_TYPE; } -/// Object-safe wrapper trait around [`Template`] implementers +/// [`dyn`-compatible] wrapper trait around [`Template`] implementers /// -/// This trades reduced performance (mostly due to writing into `dyn Write`) for object safety. +/// This trades reduced performance (mostly due to writing into `dyn Write`) for dyn-compatibility. +/// +/// [`dyn`-compatible]: pub trait DynTemplate { /// Helper method which allocates a new `String` and renders into it fn dyn_render(&self) -> Result; From c02b2519c854cea495cf6b82843d25a2d3a609ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Kijewski?= Date: Sat, 12 Oct 2024 17:01:35 +0200 Subject: [PATCH 2/2] Make simple forwarding methods `#[inline]` --- rinja/src/lib.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rinja/src/lib.rs b/rinja/src/lib.rs index c30744f9a..bcd691de4 100644 --- a/rinja/src/lib.rs +++ b/rinja/src/lib.rs @@ -201,33 +201,39 @@ pub trait DynTemplate { } impl DynTemplate for T { + #[inline] fn dyn_render(&self) -> Result { - ::render(self) + Self::render(self) } + #[inline] fn dyn_render_into(&self, writer: &mut dyn fmt::Write) -> Result<()> { - ::render_into(self, writer) + Self::render_into(self, writer) } #[inline] fn dyn_write_into(&self, writer: &mut dyn io::Write) -> io::Result<()> { - ::write_into(self, writer) + Self::write_into(self, writer) } + #[inline] fn extension(&self) -> Option<&'static str> { Self::EXTENSION } + #[inline] fn size_hint(&self) -> usize { Self::SIZE_HINT } + #[inline] fn mime_type(&self) -> &'static str { Self::MIME_TYPE } } impl fmt::Display for dyn DynTemplate { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.dyn_render_into(f).map_err(|_| fmt::Error {}) }