Skip to main content

AddTo

Trait AddTo 

Source
pub trait AddTo<Collector: ?Sized> {
    type Handle<'a>
       where Collector: 'a;

    // Required method
    fn add_to(self, collector: &mut Collector) -> Self::Handle<'_>;
}
Expand description

Trait for adding a value to a child collector.

The element! macro dispatches all child additions through this trait, enabling compile-time type checking of parent-child relationships. If you try to nest a component inside a parent that doesn’t accept it, you’ll get a compile error rather than a runtime panic.

§Implementations

  • Blanket impl: any Component can be added to Elements.
  • Data types: Span converts Into<TextChild>, String converts Into<TextChild>. These produce compile errors if used in the wrong context.

Required Associated Types§

Source

type Handle<'a> where Collector: 'a

Handle returned after adding. Supports .key() / .width() chaining.

Required Methods§

Source

fn add_to(self, collector: &mut Collector) -> Self::Handle<'_>

Add this value to the collector, returning a handle for chaining .key() and .width().

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.

Implementations on Foreign Types§

Source§

impl AddTo<Elements> for String

String → Elements: creates a Text component with the string as content.

This powers the element! string literal sugar — "hello" becomes a Text component. The same AddTo dispatch also works inside data children contexts (e.g., Text { "hello" }) via the Into<TextChild> blanket impl.

Source§

type Handle<'a> = ElementHandle<'a>

Source§

fn add_to(self, els: &mut Elements) -> ElementHandle<'_>

Implementors§

Source§

impl<C: Component> AddTo<Elements> for ComponentWithSlot<C>

Source§

impl<C: Component> AddTo<Elements> for C

Blanket: any Component can be added to Elements.

Source§

impl<T, V: Into<T>> AddTo<DataChildren<T>> for V

Any type that converts Into<T> can be added to a DataChildren<T> collector.

Source§

type Handle<'a> = DataHandle where T: 'a