Skip to main content

Application

Trait Application 

Source
pub trait Application: Sized + 'static {
    type Message: Clone + 'static;
    type Color: PixelColor;
    type Screen: ScreenView<Self::Color, Self::Message>;

    // Required methods
    fn init() -> (Self, Task<Self::Message>);
    fn update(&mut self, message: Self::Message) -> Task<Self::Message>;
    fn view(&self) -> &Self::Screen;

    // Provided method
    fn subscription(&self) -> Subscription<Self::Message> { ... }
}
Expand description

An application running under the Runtime.

libcosmic-shaped: the user defines an application type, not an application value. The runtime calls Application::init to obtain the initial state and a startup Task (used to kick off async loads — read config, fetch initial data, etc.).

Required Associated Types§

Source

type Message: Clone + 'static

Application message type. Must be Clone for runtime dispatch through update.

Source

type Color: PixelColor

Pixel color type used by this application’s display.

Source

type Screen: ScreenView<Self::Color, Self::Message>

Concrete screen type — typically a user-defined enum dispatching to per-screen structs via match arms.

Required Methods§

Source

fn init() -> (Self, Task<Self::Message>)

Construct the initial application state and a startup task. Called once by the runtime before the event loop starts.

Source

fn update(&mut self, message: Self::Message) -> Task<Self::Message>

Mutate state in response to a message.

Source

fn view(&self) -> &Self::Screen

The currently-active screen (for drawing).

Provided Methods§

Source

fn subscription(&self) -> Subscription<Self::Message>

Long-lived message sources. Called once at startup and after every processed message — refresh is automatic. Identity comes from the Recipe inside, so changing what’s returned (or returning Subscription::none()) cleanly replaces the subscription. Default: none.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§