pub trait StateExt {
// Required methods
fn get_str(&self, key: &str) -> Option<&str>;
fn get_bool(&self, key: &str) -> Option<bool>;
fn get_u64(&self, key: &str) -> Option<u64>;
fn get_i64(&self, key: &str) -> Option<i64>;
fn get_f64(&self, key: &str) -> Option<f64>;
fn get_json<T>(&self, key: &str) -> Result<T, StateError>
where T: DeserializeOwned;
fn require<T>(&self, key: &str) -> Result<T, StateError>
where T: DeserializeOwned;
fn set<T>(&mut self, key: impl Into<String>, value: T)
where T: Serialize;
fn remove(&mut self, key: &str) -> Option<Value>;
fn contains(&self, key: &str) -> bool;
fn reduce(
&mut self,
key: &str,
value: Value,
reducer: &StateReducer,
) -> Result<(), String>;
fn append_array(&mut self, key: &str, items: Value) -> Result<(), String>;
}Expand description
State 扩展方法 — 通过 Trait 为 HashMap 添加强类型访问与 Reducer 能力。
Required Methods§
Sourcefn get_json<T>(&self, key: &str) -> Result<T, StateError>where
T: DeserializeOwned,
fn get_json<T>(&self, key: &str) -> Result<T, StateError>where
T: DeserializeOwned,
反序列化为强类型。
Sourcefn require<T>(&self, key: &str) -> Result<T, StateError>where
T: DeserializeOwned,
fn require<T>(&self, key: &str) -> Result<T, StateError>where
T: DeserializeOwned,
获取并反序列化为强类型。key 不存在时返回错误。
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".