Skip to main content

State

Type Alias State 

Source
pub type State = HashMap<String, Value>;
Expand description

Graph 共享状态。

Aliased Type§

pub struct State { /* private fields */ }

Trait Implementations§

Source§

impl StateExt for State

Source§

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

获取 String 值。
Source§

fn get_bool(&self, key: &str) -> Option<bool>

获取 bool 值。
Source§

fn get_u64(&self, key: &str) -> Option<u64>

获取 u64 值。
Source§

fn get_i64(&self, key: &str) -> Option<i64>

获取 i64 值。
Source§

fn get_f64(&self, key: &str) -> Option<f64>

获取 f64 值。
Source§

fn get_json<T>(&self, key: &str) -> Result<T, StateError>

反序列化为强类型。
Source§

fn require<T>(&self, key: &str) -> Result<T, StateError>

获取并反序列化为强类型。key 不存在时返回错误。
Source§

fn set<T>(&mut self, key: impl Into<String>, value: T)
where T: Serialize,

设置值(自动序列化)。
Source§

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

移除并返回值。
Source§

fn contains(&self, key: &str) -> bool

检查 key 是否存在。
Source§

fn reduce( &mut self, key: &str, value: Value, reducer: &StateReducer, ) -> Result<(), String>

使用 Reducer 合并值到指定 key。
Source§

fn append_array(&mut self, key: &str, items: Value) -> Result<(), String>

追加模式 — 内置的数组追加 Reducer。