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
use super::Node;

/// Items that implement `IntoNodes`:
/// - Can be used in `nodes!`.
/// - Can be returned from `view`.
pub trait IntoNodes<Ms> {
    /// Converts item or items to `Vec<Node<Ms>`.
    fn into_nodes(self) -> Vec<Node<Ms>>;
}

impl<Ms> IntoNodes<Ms> for Node<Ms> {
    fn into_nodes(self) -> Vec<Node<Ms>> {
        vec![self]
    }
}

impl<Ms, T: IntoNodes<Ms>> IntoNodes<Ms> for Option<T> {
    fn into_nodes(self) -> Vec<Node<Ms>> {
        self.map(IntoNodes::into_nodes).unwrap_or_default()
    }
}

impl<Ms> IntoNodes<Ms> for Vec<Node<Ms>> {
    fn into_nodes(self) -> Vec<Node<Ms>> {
        self
    }
}