Skip to main content

rosace_core/
child_container.rs

1use crate::element::Element;
2
3/// Implemented by builder types that accumulate child `Element`s.
4///
5/// All methods consume `self` and return `Self` to support chained builder syntax.
6pub trait ChildContainer: Sized {
7    /// Appends a single child element.
8    fn child(self, element: impl Into<Element>) -> Self;
9
10    /// Appends a homogeneous collection of child elements.
11    fn children<E: Into<Element>>(self, elements: Vec<E>) -> Self;
12
13    /// Appends a child element only if `element` is `Some`.
14    fn child_if(self, element: Option<impl Into<Element>>) -> Self {
15        match element {
16            Some(e) => self.child(e),
17            None => self,
18        }
19    }
20
21    /// Inserts a child element at the front of the child list.
22    fn prepend(self, element: impl Into<Element>) -> Self;
23}