pub trait Model: Sized {
type Message: From<Event> + Send + 'static;
// Required methods
fn update(&mut self, msg: Self::Message) -> Cmd<Self::Message>;
fn view(&self, frame: &mut Frame<'_>);
// Provided methods
fn init(&mut self) -> Cmd<Self::Message> { ... }
fn subscriptions(&self) -> Vec<Box<dyn Subscription<Self::Message>>> { ... }
}Expand description
The Model trait defines application state and behavior.
Implementations define how the application responds to events and renders its current state.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn init(&mut self) -> Cmd<Self::Message>
fn init(&mut self) -> Cmd<Self::Message>
Initialize the model with startup commands.
Called once when the program starts. Return commands to execute initial side effects like loading data.
Sourcefn subscriptions(&self) -> Vec<Box<dyn Subscription<Self::Message>>>
fn subscriptions(&self) -> Vec<Box<dyn Subscription<Self::Message>>>
Declare active subscriptions.
Called after each update(). The runtime compares the returned set
(by SubId) against currently running subscriptions and starts/stops
as needed. Returning an empty vec stops all subscriptions.
§Default
Returns an empty vec (no subscriptions).
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.