Skip to main content

Component

Trait Component 

Source
pub trait Component {
    type Message;

    // Required methods
    fn on_event(
        &mut self,
        event: &Event,
    ) -> impl Future<Output = Option<Vec<Self::Message>>>;
    fn render(&mut self, ctx: &ViewContext) -> Frame;
}
Expand description

A component that can process events and emit typed messages.

Required Associated Types§

Source

type Message

The message type emitted by this widget.

Required Methods§

Source

fn on_event( &mut self, event: &Event, ) -> impl Future<Output = Option<Vec<Self::Message>>>

Process an event and return the outcome.

  • None — event not recognized, propagate to parent
  • Some(vec![]) — event consumed, no messages
  • Some(vec![msg, ...]) — event consumed, emit messages
Source

fn render(&mut self, ctx: &ViewContext) -> Frame

Render the current state to a frame.

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§