Skip to main content

ChildrenExt

Trait ChildrenExt 

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>(self, child: Option<C>) -> Self
       where C: IntoElement { ... }
    fn child<C>(self, child: C) -> Self
       where C: IntoElement { ... }
}
Expand description

Trait for composing child elements.

Required Methods§

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§

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()))

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

Appends a child only when the Option is Some.

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

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

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§