pub struct JsonFileStore { /* private fields */ }Expand description
A StateStore that persists snapshots to a JSON file on disk.
Open one with JsonFileStore::open (which loads any existing file), then
hand it to Bot::with_state_store:
use std::sync::Arc;
use rustrade::JsonFileStore;
let store = Arc::new(JsonFileStore::open("/var/lib/fks/bot-risk.json").await?);
// Bot::builder()...build()?.with_state_store(store)Implementations§
Source§impl JsonFileStore
impl JsonFileStore
Sourcepub async fn open(path: impl Into<PathBuf>) -> Result<Self>
pub async fn open(path: impl Into<PathBuf>) -> Result<Self>
Open (or create) a store at path, loading any existing snapshot map.
A missing file starts empty (first boot). The parent directory is created if needed.
§Errors
Error::Storage if the parent dir can’t be created, the file can’t be
read, or an existing file is corrupt (not valid JSON object) — corruption
is surfaced rather than silently dropping persisted state.
Trait Implementations§
Source§impl StateStore for JsonFileStore
impl StateStore for JsonFileStore
Source§fn load<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn load<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<Option<Value>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Auto Trait Implementations§
impl !Freeze for JsonFileStore
impl !RefUnwindSafe for JsonFileStore
impl Send for JsonFileStore
impl Sync for JsonFileStore
impl Unpin for JsonFileStore
impl UnsafeUnpin for JsonFileStore
impl UnwindSafe for JsonFileStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more