Skip to main content

App

Trait App 

Source
pub trait App: Sized {
    type Action: DeserializeOwned;
    type Effect: Serialize;

    // Required methods
    fn boot(boot: &Value, ctx: &mut Ctx<Self::Effect>) -> Self;
    fn update(&mut self, action: Self::Action, ctx: &mut Ctx<Self::Effect>);
    fn resolve(
        &mut self,
        id: u64,
        result: Result<Value, String>,
        ctx: &mut Ctx<Self::Effect>,
    );
    fn view(&self, key: &str) -> Option<Value>;
    fn screen(&self) -> String;
    fn actions(&self) -> Vec<ActionSpec>;

    // Provided methods
    fn pointer(&mut self, _pointer: Pointer, _ctx: &mut Ctx<Self::Effect>) { ... }
    fn blob(&mut self, _name: &str, _bytes: &[u8], _ctx: &mut Ctx<Self::Effect>) { ... }
}
Expand description

The app: a model plus pure transitions. All time comes from ctx.at().

Required Associated Types§

Source

type Action: DeserializeOwned

User intents, decoded from the act field (serde external tagging: "Inc", {"Add":{"n":2}}).

Source

type Effect: Serialize

The app’s own effects, next to the built-in ones. NoEffect for none.

Required Methods§

Source

fn boot(boot: &Value, ctx: &mut Ctx<Self::Effect>) -> Self

Build the model from the shell’s boot facts.

Source

fn update(&mut self, action: Self::Action, ctx: &mut Ctx<Self::Effect>)

Source

fn resolve( &mut self, id: u64, result: Result<Value, String>, ctx: &mut Ctx<Self::Effect>, )

The answer to effect id: Ok(value) or Err(message).

Source

fn view(&self, key: &str) -> Option<Value>

The JSON of one view key, or None when the key is unknown.

Source

fn screen(&self) -> String

Current screen name; its view key is the same name.

Source

fn actions(&self) -> Vec<ActionSpec>

Actions legal right now.

Provided Methods§

Source

fn pointer(&mut self, _pointer: Pointer, _ctx: &mut Ctx<Self::Effect>)

Typed pointer fast path. Mark views dirty through ctx.

Source

fn blob(&mut self, _name: &str, _bytes: &[u8], _ctx: &mut Ctx<Self::Effect>)

Large binary input (provide_blob).

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§