1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
use super::html::{Document, Node, TextNode}; pub trait IntoDocument { fn into_document(self) -> Document; } pub trait IntoNode : Sized { fn into_node(self) -> Option<Node>; } pub trait IntoNodes { fn into_nodes(self) -> Vec<Node>; } impl<T: IntoNode> IntoNodes for T { fn into_nodes(self) -> Vec<Node> { self.into_node().into_iter().collect() } } pub trait IntoNodesIter { fn into_nodes(self) -> Vec<Node>; } impl<I: IntoNodes, T: IntoIterator<Item = I>> IntoNodesIter for T { fn into_nodes(self) -> Vec<Node> { self.into_iter().flat_map(|n| n.into_nodes()).collect() } } impl IntoNode for String { fn into_node(self) -> Option<Node> { Some(TextNode::new(self).into()) } } impl<'a> IntoNode for &'a str { fn into_node(self) -> Option<Node> { Some(TextNode::new(self).into()) } }