pub trait Model: Send + 'static {
// Required methods
fn init(&self) -> Option<Cmd>;
fn update(&mut self, msg: Message) -> Option<Cmd>;
fn view(&self) -> String;
}Expand description
The Model trait for TUI applications.
Implement this trait to define your application’s behavior.
§Example
use bubbletea::{Model, Message, Cmd};
struct Counter { count: i32 }
impl Model for Counter {
fn init(&self) -> Option<Cmd> { None }
fn update(&mut self, msg: Message) -> Option<Cmd> {
if msg.is::<i32>() {
self.count += msg.downcast::<i32>().unwrap();
}
None
}
fn view(&self) -> String {
format!("Count: {}", self.count)
}
}Required Methods§
Sourcefn init(&self) -> Option<Cmd>
fn init(&self) -> Option<Cmd>
Initialize the model and return an optional startup command.
This is called once when the program starts.