Skip to main content

Model

Trait Model 

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

    // Required methods
    fn update(&mut self, msg: Self::Msg) -> Command<Self::Msg>;
    fn view(&self, frame: &mut Frame<'_>);
    fn handle_event(&self, event: Event) -> Option<Self::Msg>;

    // Provided methods
    fn init(&self) -> Command<Self::Msg> { ... }
    fn register_ontology(&self, _registry: &mut OntologyRegistry) { ... }
}
Expand description

The core trait for application models (Elm Architecture).

Required Associated Types§

Source

type Msg: Send + 'static

The message type for this application.

Required Methods§

Source

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

Handle an event and return an updated model plus optional command.

Source

fn view(&self, frame: &mut Frame<'_>)

Render the model into the terminal frame.

Source

fn handle_event(&self, event: Event) -> Option<Self::Msg>

Convert a raw terminal event into an application message. Return None to ignore the event.

Provided Methods§

Source

fn init(&self) -> Command<Self::Msg>

Called once at startup. Return an initial command.

Source

fn register_ontology(&self, _registry: &mut OntologyRegistry)

Called when the agent ontology is exported. Override to customize the registry.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§