on master help sign in
Add doc comment explaining motivation for `Node`'s `IntoIterator` impl
5e9415fNick Fitzgerald
src/node.rs+7
@@ -150,6 +150,13 @@ impl<'a> Node<'a> {
150 }
150 }
151}
151}
152
152
153+/// A node can become an iterator that yields the node itself once.
154+///
155+/// This implementation of `IntoIterator` mostly exists to improve the
156+/// `typed-html` ergonomics, where the macro invokes `.into_iter()` on the child
157+/// contents of a tag. By implementing `IntoIterator` here, we avoid having to
158+/// do nasty shenanigans like `<p>vec![$contents]</p>` instead of plain old
159+/// `<p>$contents</p>`.
153impl<'a> IntoIterator for Node<'a> {
160impl<'a> IntoIterator for Node<'a> {
154 type Item = Node<'a>;
161 type Item = Node<'a>;
155 type IntoIter = iter::Once<Self::Item>;
162 type IntoIter = iter::Once<Self::Item>;