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/benches/utils.rs | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'log_db/benches/utils.rs') diff --git a/log_db/benches/utils.rs b/log_db/benches/utils.rs index d25a5af..33a45cf 100644 --- a/log_db/benches/utils.rs +++ b/log_db/benches/utils.rs @@ -33,25 +33,19 @@ impl Into for Field { } } -impl Inst { - pub fn fields() -> Vec { - vec![Field::Id, Field::Name, Field::Data] - } - pub fn primary_key() -> Field { - Field::Id - } - pub fn secondary_keys() -> Vec { - vec![Field::Name] - } - - pub fn into_record(self) -> Vec { +impl From for Record { + fn from(inst: Inst) -> Self { vec![ - Value::Int(self.id), - Value::String(self.name), - Value::Bytes(self.data), + Value::Int(inst.id), + Value::String(inst.name), + Value::Bytes(inst.data), ] + .into() } - pub fn from_record(record: Vec) -> Self { +} + +impl From for Inst { + fn from(record: Record) -> Self { let mut it = record.into_iter(); Inst { id: match it.next().unwrap() { @@ -70,6 +64,18 @@ impl Inst { } } +impl Inst { + pub fn fields() -> Vec { + vec![Field::Id, Field::Name, Field::Data] + } + pub fn primary_key() -> Field { + Field::Id + } + pub fn secondary_keys() -> Vec { + vec![Field::Name] + } +} + // Function to generate a random integer pub fn random_int(from: i64, to: i64) -> i64 { let mut rng = rand::thread_rng(); @@ -98,7 +104,7 @@ pub fn random_inst(from_id: i64, to_id: i64) -> Inst { } pub fn prefill_db( - db: &mut DB, + db: &mut DB, insts: &mut Vec, n_records: usize, compact: bool, -- cgit v1.3