use std::fmt::{self, Display, Formatter};
use super::write_children;
use crate::Node;
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Fragment {
pub children: Vec<Node>,
}
impl Fragment {
pub const EMPTY: Self = Self {
children: Vec::new(),
};
}
impl Default for Fragment {
fn default() -> Self {
Self::EMPTY
}
}
impl Display for Fragment {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write_children(f, &self.children, true)
}
}
impl<N> FromIterator<N> for Fragment
where
N: Into<Node>,
{
fn from_iter<I>(iter: I) -> Self
where
I: IntoIterator<Item = N>,
{
Self {
children: iter.into_iter().map(Into::into).collect(),
}
}
}
impl<I, N> From<I> for Fragment
where
I: IntoIterator<Item = N>,
N: Into<Node>,
{
fn from(iter: I) -> Self {
Self::from_iter(iter)
}
}