From 7e8e688e2e58f9c944b941e768ab7b034a348a1f Mon Sep 17 00:00:00 2001 From: Vika Date: Thu, 1 Aug 2024 19:48:37 +0300 Subject: 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. --- src/database/memory.rs | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'src/database/memory.rs') 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>>, pub channels: Arc>>>, @@ -16,6 +16,10 @@ pub struct MemoryStorage { #[async_trait] impl Storage for MemoryStorage { + async fn new(_url: &url::Url) -> Result { + Ok(Self::default()) + } + async fn categories(&self, _url: &str) -> Result> { 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())), - } - } -} -- cgit 1.4.1