ChildrenExt

Trait ChildrenExt 

Source
pub trait ChildrenExt: Sized {
    // Required method
    fn get_children(&mut self) -> &mut Vec<Element>;

    // Provided methods
    fn children(self, children: impl IntoIterator<Item = Element>) -> Self { ... }
    fn maybe_child<C: IntoElement>(self, child: Option<C>) -> Self { ... }
    fn child<C: IntoElement>(self, child: C) -> Self { ... }
}
Expand description

Trait for composing child elements.

Required Methods§

Source

fn get_children(&mut self) -> &mut Vec<Element>

Returns a mutable reference to the internal children vector.

§Example
impl ChildrenExt for MyElement {
    fn get_children(&mut self) -> &mut Vec<Element> {
        &mut self.elements
    }
}

Provided Methods§

Source

fn children(self, children: impl IntoIterator<Item = Element>) -> Self

Extends the children with an iterable of Elements.

§Example
rect().children(["Hello", "World"].map(|t| label().text(t).into_element()))
Source

fn maybe_child<C: IntoElement>(self, child: Option<C>) -> Self

Appends a child only when the Option is Some.

§Example
rect().maybe_child(show_badge.then(|| label().text("New")))
Source

fn child<C: IntoElement>(self, child: C) -> Self

Appends a single child element.

§Example
rect().child(label().text("Hello"))

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§