funpay_client/storage/
memory.rs1use crate::storage::StateStorage;
2use async_trait::async_trait;
3use std::collections::HashMap;
4use std::sync::RwLock;
5
6pub struct InMemoryStorage {
7 data: RwLock<HashMap<i64, i64>>,
8}
9
10impl InMemoryStorage {
11 pub fn new() -> Self {
12 Self {
13 data: RwLock::new(HashMap::new()),
14 }
15 }
16}
17
18impl Default for InMemoryStorage {
19 fn default() -> Self {
20 Self::new()
21 }
22}
23
24#[async_trait]
25impl StateStorage for InMemoryStorage {
26 async fn load(&self) -> anyhow::Result<HashMap<i64, i64>> {
27 Ok(self.data.read().unwrap().clone())
28 }
29
30 async fn save(&self, data: &HashMap<i64, i64>) -> anyhow::Result<()> {
31 *self.data.write().unwrap() = data.clone();
32 Ok(())
33 }
34}