diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2023-12-21 15:36:05 +0100 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2023-12-21 15:36:05 +0100 |
commit | e9aabe8e82e3c3a8190c0224cd1fdf2fc4d2505a (patch) | |
tree | 950c3030d6cd58b39afe36147fb19228fe205e3d /src/storage | |
parent | a3a9f87d2c1d2f1c01ecba3a00c592e477a6b22b (diff) | |
download | aerogramme-e9aabe8e82e3c3a8190c0224cd1fdf2fc4d2505a.tar.gz aerogramme-e9aabe8e82e3c3a8190c0224cd1fdf2fc4d2505a.zip |
move storage logic into the storage module
Diffstat (limited to 'src/storage')
-rw-r--r-- | src/storage/in_memory.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/storage/in_memory.rs b/src/storage/in_memory.rs index 00eedab..fb6e599 100644 --- a/src/storage/in_memory.rs +++ b/src/storage/in_memory.rs @@ -9,6 +9,22 @@ use tokio::sync::Notify; /// It means that when a user disconnects, its data are lost. /// It's intended only for basic debugging, do not use it for advanced tests... +#[derive(Debug, Default)] +pub struct MemDb(tokio::sync::Mutex<HashMap<String, Arc<MemBuilder>>>); +impl MemDb { + pub fn new() -> Self { + Self(tokio::sync::Mutex::new(HashMap::new())) + } + + pub async fn builder(&self, username: &str) -> Arc<MemBuilder> { + let mut global_storage = self.0.lock().await; + global_storage + .entry(username.to_string()) + .or_insert(MemBuilder::new(username)) + .clone() + } +} + #[derive(Debug, Clone)] enum InternalData { Tombstone, |