diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2023-11-02 10:38:47 +0100 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2023-11-02 10:38:47 +0100 |
commit | 9aa58194d44fef8b0b916f6c96edd124ce13bf7b (patch) | |
tree | 7d8fecdddad2212096fd8a36a03805d5aaee3114 /src/storage | |
parent | 415f51ac4cfc723bbf6f0c08d57fb86e96c665a2 (diff) | |
download | aerogramme-9aa58194d44fef8b0b916f6c96edd124ce13bf7b.tar.gz aerogramme-9aa58194d44fef8b0b916f6c96edd124ce13bf7b.zip |
try dynamic dispatch
Diffstat (limited to 'src/storage')
-rw-r--r-- | src/storage/garage.rs | 17 | ||||
-rw-r--r-- | src/storage/in_memory.rs | 17 | ||||
-rw-r--r-- | src/storage/mod.rs | 28 |
3 files changed, 41 insertions, 21 deletions
diff --git a/src/storage/garage.rs b/src/storage/garage.rs index 965953e..f2cc216 100644 --- a/src/storage/garage.rs +++ b/src/storage/garage.rs @@ -1,45 +1,46 @@ use crate::storage::*; +#[derive(Clone, Debug)] pub struct GrgCreds {} pub struct GrgStore {} pub struct GrgRef {} pub struct GrgValue {} impl IRowBuilder for GrgCreds { - fn row_store(&self) -> GrgStore { + fn row_store(&self) -> RowStore { unimplemented!(); } } impl IRowStore for GrgStore { - fn new_row(&self, partition: &str, sort: &str) -> GrgRef { + fn new_row(&self, partition: &str, sort: &str) -> RowRef { unimplemented!(); } } impl IRowRef for GrgRef { - fn set_value(&self, content: Vec<u8>) -> GrgValue { + fn set_value(&self, content: Vec<u8>) -> RowValue { unimplemented!(); } - async fn fetch(&self) -> Result<GrgValue, Error> { + fn fetch(&self) -> AsyncResult<RowValue> { unimplemented!(); } - async fn rm(&self) -> Result<(), Error> { + fn rm(&self) -> AsyncResult<()> { unimplemented!(); } - async fn poll(&self) -> Result<Option<GrgValue>, Error> { + fn poll(&self) -> AsyncResult<Option<RowValue>> { unimplemented!(); } } impl IRowValue for GrgValue { - fn to_ref(&self) -> GrgRef { + fn to_ref(&self) -> RowRef { unimplemented!(); } fn content(&self) -> ConcurrentValues { unimplemented!(); } - async fn push(&self) -> Result<(), Error> { + fn push(&self) -> AsyncResult<()> { unimplemented!(); } } diff --git a/src/storage/in_memory.rs b/src/storage/in_memory.rs index dc3d1e1..fe7c93f 100644 --- a/src/storage/in_memory.rs +++ b/src/storage/in_memory.rs @@ -1,45 +1,46 @@ use crate::storage::*; +#[derive(Clone, Debug)] pub struct MemCreds {} pub struct MemStore {} pub struct MemRef {} pub struct MemValue {} impl IRowBuilder for MemCreds { - fn row_store(&self) -> MemStore { + fn row_store(&self) -> RowStore { unimplemented!(); } } impl IRowStore for MemStore { - fn new_row(&self, partition: &str, sort: &str) -> MemRef { + fn new_row(&self, partition: &str, sort: &str) -> RowRef { unimplemented!(); } } impl IRowRef for MemRef { - fn set_value(&self, content: Vec<u8>) -> MemValue { + fn set_value(&self, content: Vec<u8>) -> RowValue { unimplemented!(); } - async fn fetch(&self) -> Result<MemValue, Error> { + fn fetch(&self) -> AsyncResult<RowValue> { unimplemented!(); } - async fn rm(&self) -> Result<(), Error> { + fn rm(&self) -> AsyncResult<()> { unimplemented!(); } - async fn poll(&self) -> Result<Option<MemValue>, Error> { + fn poll(&self) -> AsyncResult<Option<RowValue>> { unimplemented!(); } } impl IRowValue for MemValue { - fn to_ref(&self) -> MemRef { + fn to_ref(&self) -> RowRef { unimplemented!(); } fn content(&self) -> ConcurrentValues { unimplemented!(); } - async fn push(&self) -> Result<(), Error> { + fn push(&self) -> AsyncResult<()> { unimplemented!(); } } diff --git a/src/storage/mod.rs b/src/storage/mod.rs index 82f7c6a..b5c8518 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -8,6 +8,8 @@ * into the object system so it is not exposed. */ +use futures::future::BoxFuture; + pub mod in_memory; pub mod garage; @@ -32,13 +34,29 @@ pub struct Engine { pub bucket: String, pub row: RowBuilder, } +impl Clone for Engine { + fn clone(&self) -> Self { + Engine { + bucket: "test".into(), + row: Box::new(in_memory::MemCreds{}) + } + } +} +impl std::fmt::Debug for Engine { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("Engine").field("bucket", &self.bucket).finish() + } +} + +// A result +pub type AsyncResult<'a, T> = BoxFuture<'a, Result<T, Error>>; // ------ Row Builder pub trait IRowBuilder { fn row_store(&self) -> RowStore; } -pub type RowBuilder = Box<dyn IRowBuilder>; +pub type RowBuilder = Box<dyn IRowBuilder + Send + Sync>; // ------ Row Store pub trait IRowStore @@ -51,9 +69,9 @@ type RowStore = Box<dyn IRowStore>; pub trait IRowRef { fn set_value(&self, content: Vec<u8>) -> RowValue; - async fn fetch(&self) -> Result<RowValue, Error>; - async fn rm(&self) -> Result<(), Error>; - async fn poll(&self) -> Result<Option<RowValue>, Error>; + fn fetch(&self) -> AsyncResult<RowValue>; + fn rm(&self) -> AsyncResult<()>; + fn poll(&self) -> AsyncResult<Option<RowValue>>; } type RowRef = Box<dyn IRowRef>; @@ -61,6 +79,6 @@ pub trait IRowValue { fn to_ref(&self) -> RowRef; fn content(&self) -> ConcurrentValues; - async fn push(&self) -> Result<(), Error>; + fn push(&self) -> AsyncResult<()>; } type RowValue = Box<dyn IRowValue>; |