Skip to main content

Model

Trait Model 

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

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

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

A TEA model with string-based rendering.

Implement this trait for simple applications that render directly to a string. For most use cases, prefer ElementModel which provides Flexbox layout.

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

Render the current state to a string.

Provided Methods§

Source

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

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

Source

fn cursor(&self) -> Option<(u16, u16)>

Where to place the real terminal cursor as (column, row), or None to keep it hidden. Returning a position shows a normal blinking cursor at the text insertion point — the correct behaviour for input fields (including wide CJK glyphs), instead of a faked reverse-video block.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§