rstml_component/
builtins.rs

1use crate::{HtmlComponent, HtmlContent, HtmlFormatter};
2use std::fmt;
3
4pub struct For<I, F>
5where
6	I: IntoIterator,
7	F: FnMut(&mut HtmlFormatter, <I as IntoIterator>::Item) -> fmt::Result,
8{
9	pub items: I,
10	pub children: F,
11}
12
13impl<I, F> HtmlComponent for For<I, F>
14where
15	I: IntoIterator,
16	F: FnMut(&mut HtmlFormatter, <I as IntoIterator>::Item) -> fmt::Result,
17{
18	type Content = Self;
19
20	fn into_content(self) -> Self::Content {
21		self
22	}
23}
24
25impl<I, F> HtmlContent for For<I, F>
26where
27	I: IntoIterator,
28	F: FnMut(&mut HtmlFormatter, <I as IntoIterator>::Item) -> fmt::Result,
29{
30	fn fmt(self, formatter: &mut HtmlFormatter) -> std::fmt::Result {
31		let For {
32			items,
33			children: mut template,
34		} = self;
35
36		for item in items {
37			template(formatter, item)?;
38		}
39
40		Ok(())
41	}
42}