From daca0e6b68d32d885face00d68df5b5cb00e098b Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Fri, 21 Feb 2025 16:15:29 +0200 Subject: Remove polymorphism from DB, replace with From based approach --- log_db/src/config.rs | 44 +++++--------------------------------------- 1 file changed, 5 insertions(+), 39 deletions(-) (limited to 'log_db/src/config.rs') diff --git a/log_db/src/config.rs b/log_db/src/config.rs index ec74164..e8c6fa1 100644 --- a/log_db/src/config.rs +++ b/log_db/src/config.rs @@ -1,12 +1,6 @@ use super::*; -pub struct Schema { - pub fields: Vec, - pub primary_key: F, - pub secondary_keys: Vec, -} - -pub struct ConfigBuilder { +pub struct ConfigBuilder { data_dir: Option, segment_size: Option, write_durability: Option, @@ -15,14 +9,10 @@ pub struct ConfigBuilder { fields: Option>, primary_key: Option, secondary_keys: Option>, - from_record: Option) -> T>, - into_record: Option Vec>, - - _marker: PhantomData, } -impl ConfigBuilder { - pub fn new() -> ConfigBuilder { +impl ConfigBuilder { + pub fn new() -> ConfigBuilder { ConfigBuilder { data_dir: None, segment_size: None, @@ -32,10 +22,6 @@ impl ConfigBuilder { fields: None, primary_key: None, secondary_keys: None, - from_record: None, - into_record: None, - - _marker: PhantomData, } } @@ -86,36 +72,18 @@ impl ConfigBuilder { self } - pub fn from_record(mut self, from_record: fn(Vec) -> T) -> Self { - self.from_record = Some(from_record); - self - } - - pub fn into_record(mut self, into_record: fn(T) -> Vec) -> Self { - self.into_record = Some(into_record); - self - } - - pub fn initialize(self) -> DBResult> { + pub fn initialize(self) -> DBResult { let schema = self .fields .ok_or_else(|| DBError::ValidationError("Schema not set".to_string()))?; let primary_key = self .primary_key .ok_or_else(|| DBError::ValidationError("Primary key not set".to_string()))?; - let from_record = self - .from_record - .ok_or_else(|| DBError::ValidationError("Callback from_record not set".to_string()))?; - let into_record = self - .into_record - .ok_or_else(|| DBError::ValidationError("Callback into_record not set".to_string()))?; let config = Config { schema, primary_key, secondary_keys: self.secondary_keys.unwrap_or_default(), - from_record, - into_record, data_dir: self.data_dir.clone().unwrap_or("db_data".to_string()), segment_size: self.segment_size.unwrap_or(4 * 1024 * 1024), // 4MB @@ -134,12 +102,10 @@ impl ConfigBuilder { } #[derive(Clone)] -pub struct Config { +pub struct Config { pub schema: Vec, pub primary_key: String, pub secondary_keys: Vec, - pub from_record: fn(Vec) -> T, - pub into_record: fn(T) -> Vec, pub data_dir: String, pub segment_size: usize, pub write_durability: WriteDurability, -- cgit v1.3