aboutsummaryrefslogtreecommitdiff
path: root/src/storage
diff options
context:
space:
mode:
authorQuentin Dufour <quentin@deuxfleurs.fr>2023-11-02 12:18:43 +0100
committerQuentin Dufour <quentin@deuxfleurs.fr>2023-11-02 12:18:43 +0100
commit3b363b2a7803564231e001c215ab427c99c9435b (patch)
tree01322398a509142babfb60415315da4e0d4c6527 /src/storage
parent553ea25f1854706b60ce6f087545968533ef6140 (diff)
downloadaerogramme-3b363b2a7803564231e001c215ab427c99c9435b.tar.gz
aerogramme-3b363b2a7803564231e001c215ab427c99c9435b.zip
implement equality+cmp for builders based on url
Diffstat (limited to 'src/storage')
-rw-r--r--src/storage/garage.rs8
-rw-r--r--src/storage/in_memory.rs8
-rw-r--r--src/storage/mod.rs43
3 files changed, 37 insertions, 22 deletions
diff --git a/src/storage/garage.rs b/src/storage/garage.rs
index dfee88d..6dea00c 100644
--- a/src/storage/garage.rs
+++ b/src/storage/garage.rs
@@ -1,12 +1,12 @@
use crate::storage::*;
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, Hash)]
pub struct GrgCreds {}
pub struct GrgStore {}
pub struct GrgRef {}
pub struct GrgValue {}
-impl IBuilder for GrgCreds {
+impl IBuilders for GrgCreds {
fn row_store(&self) -> Result<RowStore, StorageError> {
unimplemented!();
}
@@ -14,6 +14,10 @@ impl IBuilder for GrgCreds {
fn blob_store(&self) -> Result<BlobStore, StorageError> {
unimplemented!();
}
+
+ fn url(&self) -> &str {
+ return "grg://unimplemented;"
+ }
}
impl IRowStore for GrgStore {
diff --git a/src/storage/in_memory.rs b/src/storage/in_memory.rs
index 80e7fdf..5cc8ef8 100644
--- a/src/storage/in_memory.rs
+++ b/src/storage/in_memory.rs
@@ -1,13 +1,13 @@
use futures::FutureExt;
use crate::storage::*;
-#[derive(Clone, Debug)]
+#[derive(Clone, Debug, Hash)]
pub struct FullMem {}
pub struct MemStore {}
pub struct MemRef {}
pub struct MemValue {}
-impl IBuilder for FullMem {
+impl IBuilders for FullMem {
fn row_store(&self) -> Result<RowStore, StorageError> {
unimplemented!();
}
@@ -15,6 +15,10 @@ impl IBuilder for FullMem {
fn blob_store(&self) -> Result<BlobStore, StorageError> {
unimplemented!();
}
+
+ fn url(&self) -> &str {
+ return "mem://unimplemented;"
+ }
}
impl IRowStore for MemStore {
diff --git a/src/storage/mod.rs b/src/storage/mod.rs
index a2bdd43..0939463 100644
--- a/src/storage/mod.rs
+++ b/src/storage/mod.rs
@@ -8,6 +8,7 @@
* into the object system so it is not exposed.
*/
+use std::hash::{Hash, Hasher};
use futures::future::BoxFuture;
pub mod in_memory;
@@ -40,32 +41,38 @@ impl std::fmt::Display for StorageError {
}
impl std::error::Error for StorageError {}
-pub struct Engine {
- pub bucket: String,
- pub builders: Builder,
+// Utils
+pub type AsyncResult<'a, T> = BoxFuture<'a, Result<T, StorageError>>;
+
+// ----- Builders
+pub trait IBuilders {
+ fn row_store(&self) -> Result<RowStore, StorageError>;
+ fn blob_store(&self) -> Result<BlobStore, StorageError>;
+ fn url(&self) -> &str;
}
-impl Clone for Engine {
+pub type Builders = Box<dyn IBuilders + Send + Sync>;
+impl Clone for Builders {
fn clone(&self) -> Self {
- Engine {
- bucket: "test".into(),
- builders: Box::new(in_memory::FullMem{})
- }
+ // @FIXME write a real implementation with a box_clone function
+ Box::new(in_memory::FullMem{})
}
}
-impl std::fmt::Debug for Engine {
+impl std::fmt::Debug for Builders {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
- f.debug_struct("Engine").field("bucket", &self.bucket).finish()
+ f.write_str("aerogramme::storage::Builder")
}
}
-
-// Utils
-pub type AsyncResult<'a, T> = BoxFuture<'a, Result<T, StorageError>>;
-
-pub trait IBuilder {
- fn row_store(&self) -> Result<RowStore, StorageError>;
- fn blob_store(&self) -> Result<BlobStore, StorageError>;
+impl PartialEq for Builders {
+ fn eq(&self, other: &Self) -> bool {
+ self.url() == other.url()
+ }
+}
+impl Eq for Builders {}
+impl Hash for Builders {
+ fn hash<H: Hasher>(&self, state: &mut H) {
+ self.url().hash(state);
+ }
}
-pub type Builder = Box<dyn IBuilder + Send + Sync>;
// ------ Row
pub trait IRowStore