Program

Trait Program 

Source
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:

  1. init initialize your state model
  2. update update your state model in response to messages
  3. view render your program’s UI

At minimum, you must implement view.

Required Associated Types§

Source

type Message: Send + 'static

Required Methods§

Source

fn view(&self) -> String

Render your program’s UI.

Provided Methods§

Source

fn init(&mut self, _mailbox: Mailbox<Self::Message>) -> Command<Self::Message>

Initialize your program’s state.

Source

fn exit(self)

Perform any cleanup before your application exits.

Source

fn on_event(_ev: TermEvent) -> Command<Self::Message>

Respond to any terminal events (mouse, keyboard) by generating messages.

Source

fn update(&mut self, _message: Self::Message) -> Command<Self::Message>

Update your program’s state in response to messages.

Source

fn run(self, config: &mut Config) -> Result<()>

Run your application.

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.

Implementors§