Skip to main content

Component

Derive Macro Component 

Source
#[derive(Component)]
{
    // Attributes available to this derive:
    #[component_id]
}
Expand description

Derive macro that implements the Component trait

This macro automatically implements all the boilerplate methods required by the Component trait.

By default, it looks for a field named id. You can specify a different field using the #[component_id] attribute.

§Example

#[derive(Component, Clone)]
struct MyComponent {
    id: Option<ComponentId>,  // Default field name
    // other fields...
}

// Or with a custom field name:
#[derive(Component, Clone)]
struct MyComponent {
    #[component_id]
    key: Option<ComponentId>,
    // other fields...
}

impl MyComponent {
    fn update(&self, ctx: &Context, msg: Box<dyn Message>, topic: Option<&str>) -> Action {
        // your implementation
    }

    fn view(&self, ctx: &Context) -> Node {
        // your implementation
    }
}