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) { ... }
    fn title(&self) -> &str { ... }
    fn subscriptions(&self) -> Vec<Subscription<Self::Msg>> { ... }
    fn current_route(&self) -> &str { ... }
}
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 a message and return an updated model plus optional command.

Source

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

Render the model into the GUI frame.

Source

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

Convert a raw 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.

Source

fn title(&self) -> &str

Application title (used as window title).

Source

fn subscriptions(&self) -> Vec<Subscription<Self::Msg>>

Return subscriptions for this model. Called after each update.

Source

fn current_route(&self) -> &str

Return the current route. Override for multi-page apps.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§