Skip to main content

Action

Trait Action 

Source
pub trait Action:
    Serialize
    + DeserializeOwned
    + Any
    + Send
    + Sync
    + Debug {
    // Required method
    fn static_id() -> ActionId
       where Self: Sized;

    // Provided method
    fn encode(&self) -> Vec<u8>  { ... }
}
Expand description

A strongly-typed, serialisable event payload.

Every action type must be Serialize + DeserializeOwned + Send + Sync + Debug and provide a stable ActionId via Action::static_id. The runtime uses JSON serialisation internally, so actions travel across the widget/reducer boundary without generics.

§Implementing Action

use fission_core::{Action, ActionId};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
struct SetName { name: String }

impl Action for SetName {
    fn static_id() -> ActionId {
        ActionId::from_name("my_app::SetName")
    }
}

Required Methods§

Source

fn static_id() -> ActionId
where Self: Sized,

Returns the globally unique, deterministic identifier for this action type.

Provided Methods§

Source

fn encode(&self) -> Vec<u8>

Serialises the action to JSON bytes for transport inside an ActionEnvelope.

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§