1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use crossbeam_channel::Receiver;
use std::collections::HashMap;
use crate::{BackendError, StoredValue};
pub trait StorageBackend: Send + Sync {
/// Load all persisted settings into memory. This method is called at load and on
/// watcher ticks.
fn load_all(&self) -> Result<HashMap<String, StoredValue>, BackendError>;
/// Persist a setting to the database.
///
/// ### Arguments
/// - **key** (&str): The identifier of the setting to persist.
/// - **value** (&StoredValue): The value associated with the setting's identifier.
fn set(&self, key: &str, value: &StoredValue) -> Result<(), BackendError>;
/// Remove a setting from the database.
/// ### Arguments
/// - **key** (&str): The identifier of the setting to delete.
fn delete(&self, key: &str) -> Result<(), BackendError>;
/// Subscribe to the backend storage event stream. Default returns `None`.
/// The returned receiver fires for every change, including own-process writes.
fn watch_changes(&self) -> Option<Receiver<()>> {
None
}
}
#[derive(Debug, Default)]
pub struct NoopBackend;
impl StorageBackend for NoopBackend {
fn load_all(&self) -> Result<HashMap<String, StoredValue>, BackendError> {
Ok(HashMap::new())
}
fn set(&self, _key: &str, _value: &StoredValue) -> Result<(), BackendError> {
Ok(())
}
fn delete(&self, _key: &str) -> Result<(), BackendError> {
Ok(())
}
}