Skip to main content

StateExt

Trait StateExt 

Source
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§

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

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

Source

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

Source

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".

Implementors§