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/mod.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/database/mod.rs') diff --git a/src/database/mod.rs b/src/database/mod.rs index f48b4a9..c256867 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -215,6 +215,8 @@ pub type Result = std::result::Result; /// or lock the database so that write conflicts or reading half-written data should not occur. #[async_trait] pub trait Storage: std::fmt::Debug + Clone + Send + Sync { + /// Initialize Self from a URL, possibly performing initialization. + async fn new(url: &'_ url::Url) -> Result; /// Return the list of categories used in blog posts of a specified blog. async fn categories(&self, url: &str) -> Result>; @@ -759,11 +761,9 @@ mod tests { #[tracing_test::traced_test] async fn $func_name() { let tempdir = tempfile::tempdir().expect("Failed to create tempdir"); - let backend = super::super::FileStorage::new( - tempdir.path().to_path_buf() - ) - .await - .unwrap(); + let backend = super::super::FileStorage { + root_dir: tempdir.path().to_path_buf() + }; super::$func_name(backend).await } }; -- cgit 1.4.1