pub trait Program: Sized {
type Message: Send + 'static;
// Required method
fn view(&self) -> String;
// Provided methods
fn init(
&mut self,
_mailbox: Mailbox<Self::Message>,
) -> Command<Self::Message> { ... }
fn exit(self) { ... }
fn on_event(_ev: TermEvent) -> Command<Self::Message> { ... }
fn update(&mut self, _message: Self::Message) -> Command<Self::Message> { ... }
fn run(self, config: &mut Config) -> Result<()> { ... }
}Expand description
A program describes a terminal application capable of generating and responding to messages, as well as rendering its UI to a string.
A douglas program consists of 3 main ingredients:
initinitialize your state modelupdateupdate your state model in response to messagesviewrender your program’s UI
At minimum, you must implement view.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn init(&mut self, _mailbox: Mailbox<Self::Message>) -> Command<Self::Message>
fn init(&mut self, _mailbox: Mailbox<Self::Message>) -> Command<Self::Message>
Initialize your program’s state.
Sourcefn on_event(_ev: TermEvent) -> Command<Self::Message>
fn on_event(_ev: TermEvent) -> Command<Self::Message>
Respond to any terminal events (mouse, keyboard) by generating messages.
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.