Skip to main content

State

Trait State 

Source
pub trait State:
    Serialize
    + DeserializeOwned
    + Clone
    + Send
    + Sync
    + 'static { }
Expand description

Trait for types that can be used as module state.

Any struct that implements Serialize + DeserializeOwned + Clone + Send + Sync can serve as module state. The SDK uses serde to convert between the typed state and JSON, and diffs JSON snapshots to detect which paths changed.

§Example

use serde::{Deserialize, Serialize};

#[derive(Clone, Default, Serialize, Deserialize)]
struct CounterState {
    count: i32,
    label: String,
}

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<T> State for T
where T: Serialize + DeserializeOwned + Clone + Send + Sync + 'static,

Blanket implementation: any type meeting the bounds is automatically State.