aboutsummaryrefslogtreecommitdiff
path: root/src/storage/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/storage/mod.rs')
-rw-r--r--src/storage/mod.rs43
1 files changed, 25 insertions, 18 deletions
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