diff options
author | Vika <vika@fireburn.ru> | 2024-08-01 19:48:37 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2024-08-01 20:40:00 +0300 |
commit | 7e8e688e2e58f9c944b941e768ab7b034a348a1f (patch) | |
tree | 1068469c6b9b97bac407038276fd8971b2101e48 /src/database/memory.rs | |
parent | 57a9c3c7e520714928904fc7e2ff3d62ac2b2467 (diff) | |
download | kittybox-7e8e688e2e58f9c944b941e768ab7b034a348a1f.tar.zst |
treewide: create a common method for state initialization
Now the database objects can be uniformly created from a URI. They can also optionally do sanity checks and one-time initialization.
Diffstat (limited to 'src/database/memory.rs')
-rw-r--r-- | src/database/memory.rs | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/src/database/memory.rs b/src/database/memory.rs index 56caeec..be37fed 100644 --- a/src/database/memory.rs +++ b/src/database/memory.rs @@ -8,7 +8,7 @@ use tokio::sync::RwLock; use crate::database::{ErrorKind, MicropubChannel, Result, settings, Storage, StorageError}; -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub struct MemoryStorage { pub mapping: Arc<RwLock<HashMap<String, serde_json::Value>>>, pub channels: Arc<RwLock<HashMap<url::Url, Vec<String>>>>, @@ -16,6 +16,10 @@ pub struct MemoryStorage { #[async_trait] impl Storage for MemoryStorage { + async fn new(_url: &url::Url) -> Result<Self> { + Ok(Self::default()) + } + async fn categories(&self, _url: &str) -> Result<Vec<String>> { unimplemented!() } @@ -231,18 +235,3 @@ impl Storage for MemoryStorage { } } - -impl Default for MemoryStorage { - fn default() -> Self { - Self::new() - } -} - -impl MemoryStorage { - pub fn new() -> Self { - Self { - mapping: Arc::new(RwLock::new(HashMap::new())), - channels: Arc::new(RwLock::new(HashMap::new())), - } - } -} |