diff --git a/src/templater.rs b/src/templater.rs index 29328eb9b..ecc52b5a1 100644 --- a/src/templater.rs +++ b/src/templater.rs @@ -27,6 +27,12 @@ pub trait IntoTemplate<'a, C> { fn into_template(self) -> Box + 'a>; } +impl + ?Sized> Template for &T { + fn format(&self, context: &C, formatter: &mut dyn Formatter) -> io::Result<()> { + >::format(self, context, formatter) + } +} + impl + ?Sized> Template for Box { fn format(&self, context: &C, formatter: &mut dyn Formatter) -> io::Result<()> { >::format(self, context, formatter) @@ -425,3 +431,25 @@ where (self.function)(self.property.extract(context)) } } + +pub fn format_joined( + context: &C, + formatter: &mut dyn Formatter, + contents: I, + separator: S, +) -> io::Result<()> +where + I: IntoIterator, + I::Item: Template, + S: Template, +{ + let mut contents_iter = contents.into_iter().fuse(); + if let Some(content) = contents_iter.next() { + content.format(context, formatter)?; + } + for content in contents_iter { + separator.format(context, formatter)?; + content.format(context, formatter)?; + } + Ok(()) +}