From 415f51ac4cfc723bbf6f0c08d57fb86e96c665a2 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 2 Nov 2023 09:57:58 +0100 Subject: sadly switch to dynamic dispatch --- src/storage/garage.rs | 16 ++++------------ src/storage/in_memory.rs | 16 ++++------------ src/storage/mod.rs | 48 ++++++++++++++++-------------------------------- 3 files changed, 24 insertions(+), 56 deletions(-) (limited to 'src/storage') diff --git a/src/storage/garage.rs b/src/storage/garage.rs index b883623..965953e 100644 --- a/src/storage/garage.rs +++ b/src/storage/garage.rs @@ -5,27 +5,19 @@ pub struct GrgStore {} pub struct GrgRef {} pub struct GrgValue {} -pub struct GrgTypes {} -impl Sto for GrgTypes { - type Builder=GrgCreds; - type Store=GrgStore; - type Ref=GrgRef; - type Value=GrgValue; -} - -impl RowBuilder for GrgCreds { +impl IRowBuilder for GrgCreds { fn row_store(&self) -> GrgStore { unimplemented!(); } } -impl RowStore for GrgStore { +impl IRowStore for GrgStore { fn new_row(&self, partition: &str, sort: &str) -> GrgRef { unimplemented!(); } } -impl RowRef for GrgRef { +impl IRowRef for GrgRef { fn set_value(&self, content: Vec) -> GrgValue { unimplemented!(); } @@ -40,7 +32,7 @@ impl RowRef for GrgRef { } } -impl RowValue for GrgValue { +impl IRowValue for GrgValue { fn to_ref(&self) -> GrgRef { unimplemented!(); } diff --git a/src/storage/in_memory.rs b/src/storage/in_memory.rs index 56df266..dc3d1e1 100644 --- a/src/storage/in_memory.rs +++ b/src/storage/in_memory.rs @@ -5,27 +5,19 @@ pub struct MemStore {} pub struct MemRef {} pub struct MemValue {} -pub struct MemTypes {} -impl Sto for MemTypes { - type Builder=MemCreds; - type Store=MemStore; - type Ref=MemRef; - type Value=MemValue; -} - -impl RowBuilder for MemCreds { +impl IRowBuilder for MemCreds { fn row_store(&self) -> MemStore { unimplemented!(); } } -impl RowStore for MemStore { +impl IRowStore for MemStore { fn new_row(&self, partition: &str, sort: &str) -> MemRef { unimplemented!(); } } -impl RowRef for MemRef { +impl IRowRef for MemRef { fn set_value(&self, content: Vec) -> MemValue { unimplemented!(); } @@ -40,7 +32,7 @@ impl RowRef for MemRef { } } -impl RowValue for MemValue { +impl IRowValue for MemValue { fn to_ref(&self) -> MemRef { unimplemented!(); } diff --git a/src/storage/mod.rs b/src/storage/mod.rs index ee475ee..82f7c6a 100644 --- a/src/storage/mod.rs +++ b/src/storage/mod.rs @@ -28,55 +28,39 @@ pub enum Error { Internal, } -pub trait Sto: Sized { - type Builder: RowBuilder; - type Store: RowStore; - type Ref: RowRef; - type Value: RowValue; -} - -pub struct Engine { +pub struct Engine { pub bucket: String, - pub row: T::Builder, -} - -pub enum AnyEngine { - InMemory(Engine), - Garage(Engine), -} -impl AnyEngine { - pub fn engine(&self) -> &Engine { - match self { - Self::InMemory(x) => x, - Self::Garage(x) => x, - } - } + pub row: RowBuilder, } // ------ Row Builder -pub trait RowBuilder +pub trait IRowBuilder { - fn row_store(&self) -> R::Store; + fn row_store(&self) -> RowStore; } +pub type RowBuilder = Box; // ------ Row Store -pub trait RowStore +pub trait IRowStore { - fn new_row(&self, partition: &str, sort: &str) -> R::Ref; + fn new_row(&self, partition: &str, sort: &str) -> RowRef; } +type RowStore = Box; // ------- Row Item -pub trait RowRef +pub trait IRowRef { - fn set_value(&self, content: Vec) -> R::Value; - async fn fetch(&self) -> Result; + fn set_value(&self, content: Vec) -> RowValue; + async fn fetch(&self) -> Result; async fn rm(&self) -> Result<(), Error>; - async fn poll(&self) -> Result, Error>; + async fn poll(&self) -> Result, Error>; } +type RowRef = Box; -pub trait RowValue +pub trait IRowValue { - fn to_ref(&self) -> R::Ref; + fn to_ref(&self) -> RowRef; fn content(&self) -> ConcurrentValues; async fn push(&self) -> Result<(), Error>; } +type RowValue = Box; -- cgit v1.2.3