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。
为 State 提供类型安全的读写方法。
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>
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".