Skip to main content

ElementModel

Trait ElementModel 

Source
pub trait ElementModel: Send + 'static {
    type Msg: Send + 'static;

    // Required methods
    fn update(&mut self, msg: Self::Msg) -> Option<Cmd<Self::Msg>>;
    fn view(&self) -> Element<Self::Msg>;

    // Provided method
    fn init(&mut self) -> Option<Cmd<Self::Msg>> { ... }
}
Expand description

A TEA model with Element tree rendering and Flexbox layout.

This is the recommended trait for building terminal UIs. The view() method returns an Element tree that is laid out using Flexbox and rendered incrementally.

Required Associated Types§

Source

type Msg: Send + 'static

Required Methods§

Source

fn update(&mut self, msg: Self::Msg) -> Option<Cmd<Self::Msg>>

Handle a message and update state. Return an optional command.

Source

fn view(&self) -> Element<Self::Msg>

Build the UI element tree from current state.

Provided Methods§

Source

fn init(&mut self) -> Option<Cmd<Self::Msg>>

Called once when the program starts. Return a command to perform initialization.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§