Skip to main content

App

Trait App 

Source
pub trait App {
    type Event: Unpin + Send + 'static;
    type Model;
    type ViewModel;
    type Effect: Effect + Unpin;

    // Required methods
    fn update(
        &self,
        event: Self::Event,
        model: &mut Self::Model,
    ) -> Command<Self::Effect, Self::Event>;
    fn view(&self, model: &Self::Model) -> Self::ViewModel;
}
Expand description

Implement App on your type to make it into a Crux app. Use your type implementing App as the type argument to Core or Bridge.

Required Associated Types§

Source

type Event: Unpin + Send + 'static

Event, typically an enum, defines the actions that can be taken to update the application state.

Source

type Model

Model, typically a struct defines the internal state of the application

Source

type ViewModel

ViewModel, typically a struct describes the user interface that should be displayed to the user

Source

type Effect: Effect + Unpin

Effect, the enum carrying the effect requests the app can make of the shell. Normally this type is written with the crux_macros::effect attribute macro, which implements the necessary traits for you.

Required Methods§

Source

fn update( &self, event: Self::Event, model: &mut Self::Model, ) -> Command<Self::Effect, Self::Event>

Update method defines the transition from one model state to another in response to an event.

update may mutate the model and returns a Command describing the managed side-effects to perform as a result of the event. Commands are constructed by capabilities, and combined to run sequentially or concurrently. If an event requires no side-effects, return Command::done.

Typically, update should call at least render.

Source

fn view(&self, model: &Self::Model) -> Self::ViewModel

View method is used by the Shell to request the current state of the user interface

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§