on master help sign in
Add doc comment explaining motivation for `Node`'s `IntoIterator` impl
commit5e9415f79f45005c63fd99c7750a94c6ae4e543f authorNick Fitzgerald <fitzgen@gmail.com> dateTue 19 Mar 2019, 09:53 (8 years ago) parent851e50b
1 file changed+7
src/node.rs+7
src/node.rs+7
@@ -150,6 +150,13 @@ impl<'a> Node<'a> {
150150 }
151151}
152152
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>`.
153160impl<'a> IntoIterator for Node<'a> {
154161 type Item = Node<'a>;
155162 type IntoIter = iter::Once<Self::Item>;