From 502fc8b7d05b9cd51f9ddcabe9872f86471afc94 Mon Sep 17 00:00:00 2001 From: davidemazzocchi Date: Tue, 30 Sep 2025 07:19:09 +0200 Subject: [PATCH] refactor: remove ToEAV trait in favor of Into --- 01.workspace/heave/src/imp/mod.rs | 8 ++--- 01.workspace/heave/src/lib.rs | 1 - 01.workspace/heave/src/str/catalog.rs | 4 +-- 01.workspace/heave/src/str/entity.rs | 6 ---- 01.workspace/heave/src/trt/eav.rs | 2 +- 01.workspace/heave/src/trt/mod.rs | 1 - 01.workspace/heave/src/trt/to_eav.rs | 5 ---- 01.workspace/heave/src/tst/intended_use.rs | 12 ++++---- .../heave/src/tst/rusty_budger_use.rs | 30 +++++++++---------- 9 files changed, 28 insertions(+), 41 deletions(-) delete mode 100644 01.workspace/heave/src/trt/to_eav.rs diff --git a/01.workspace/heave/src/imp/mod.rs b/01.workspace/heave/src/imp/mod.rs index 119ec13..e9243e7 100644 --- a/01.workspace/heave/src/imp/mod.rs +++ b/01.workspace/heave/src/imp/mod.rs @@ -11,10 +11,10 @@ pub mod string_from_value; // pub mod string_to_value; pub mod u64_from_value; // pub mod u64_to_value; +pub mod value_from_bool; +pub mod value_from_entity; +pub mod value_from_f64; +pub mod value_from_i64; pub mod value_from_str; pub mod value_from_string; pub mod value_from_u64; -pub mod value_from_f64; -pub mod value_from_bool; -pub mod value_from_entity; -pub mod value_from_i64; diff --git a/01.workspace/heave/src/lib.rs b/01.workspace/heave/src/lib.rs index 130d69c..4edf57b 100644 --- a/01.workspace/heave/src/lib.rs +++ b/01.workspace/heave/src/lib.rs @@ -12,7 +12,6 @@ pub use crate::str::catalog::O as Catalog; pub use crate::str::entity::O as Entity; pub use crate::str::value::E as Value; pub use crate::trt::eav::T as EAV; -pub use crate::trt::to_eav::T as ToEAV; mod sqlite { pub mod init { diff --git a/01.workspace/heave/src/str/catalog.rs b/01.workspace/heave/src/str/catalog.rs index ffdd47b..6b2a6af 100644 --- a/01.workspace/heave/src/str/catalog.rs +++ b/01.workspace/heave/src/str/catalog.rs @@ -19,12 +19,12 @@ impl O { sqlite::init::db(path); } pub fn insert(&mut self, object: impl EAV) { - let entity = object.to_eav(); + let entity = object.into(); self.items.insert(entity.id.clone(), entity); } pub fn insert_many(&mut self, objects: Vec) { for object in objects { - let entity = object.to_eav(); + let entity = object.into(); self.items.insert(entity.id.clone(), entity); } } diff --git a/01.workspace/heave/src/str/entity.rs b/01.workspace/heave/src/str/entity.rs index 1939169..917cb02 100644 --- a/01.workspace/heave/src/str/entity.rs +++ b/01.workspace/heave/src/str/entity.rs @@ -9,12 +9,6 @@ pub struct O { impl EAV for Entity {} -impl ToEAV for Entity { - fn to_eav(self) -> Entity { - self - } -} - impl O { pub fn new(class: &str) -> Self { Self { diff --git a/01.workspace/heave/src/trt/eav.rs b/01.workspace/heave/src/trt/eav.rs index 68d588a..40428c0 100644 --- a/01.workspace/heave/src/trt/eav.rs +++ b/01.workspace/heave/src/trt/eav.rs @@ -3,7 +3,7 @@ use crate::*; /// TODO: INSERT DOCUMENTATION HERE pub trait T where Self: From, - Self: ToEAV, + Self: Into, { } diff --git a/01.workspace/heave/src/trt/mod.rs b/01.workspace/heave/src/trt/mod.rs index de7e67e..08b9bcf 100644 --- a/01.workspace/heave/src/trt/mod.rs +++ b/01.workspace/heave/src/trt/mod.rs @@ -1,2 +1 @@ pub mod eav; -pub mod to_eav; diff --git a/01.workspace/heave/src/trt/to_eav.rs b/01.workspace/heave/src/trt/to_eav.rs deleted file mode 100644 index 1b33173..0000000 --- a/01.workspace/heave/src/trt/to_eav.rs +++ /dev/null @@ -1,5 +0,0 @@ -use crate::*; - -pub trait T { - fn to_eav(self) -> Entity; -} diff --git a/01.workspace/heave/src/tst/intended_use.rs b/01.workspace/heave/src/tst/intended_use.rs index 6b7a84a..212f685 100644 --- a/01.workspace/heave/src/tst/intended_use.rs +++ b/01.workspace/heave/src/tst/intended_use.rs @@ -8,13 +8,13 @@ mod tests { pub price: u64, } impl EAV for Product {} - impl ToEAV for Product { - fn to_eav(self) -> Entity { + impl From for Entity { + fn from(value: Product) -> Entity { Entity::default() .with_class("product") - .with_id(&self.id) - .with_attribute("name", self.name) - .with_attribute("price", self.price) + .with_id(&value.id) + .with_attribute("name", value.name) + .with_attribute("price", value.price) } } impl From for Product { @@ -118,7 +118,7 @@ mod tests { price: 200000u64, }; let expected_product = product.clone(); - let entity = product.to_eav(); + let entity: Entity = product.into(); let converted_product = Product::from(entity); assert_eq!(expected_product, converted_product); } diff --git a/01.workspace/heave/src/tst/rusty_budger_use.rs b/01.workspace/heave/src/tst/rusty_budger_use.rs index baff53f..ec6a97a 100644 --- a/01.workspace/heave/src/tst/rusty_budger_use.rs +++ b/01.workspace/heave/src/tst/rusty_budger_use.rs @@ -12,13 +12,13 @@ mod tests { pub category_id: String, } impl EAV for OperationToCategory {} - impl ToEAV for OperationToCategory { - fn to_eav(self) -> Entity { + impl From for Entity { + fn from(value: OperationToCategory) -> Entity { Entity::default() .with_class("operation_has_category") - .with_id(&self.id) - .with_attribute("operation_id", self.operation_id) - .with_attribute("category_id", self.category_id) + .with_id(&value.id) + .with_attribute("operation_id", value.operation_id) + .with_attribute("category_id", value.category_id) } } impl From for OperationToCategory { @@ -38,12 +38,12 @@ mod tests { pub label: String, } impl EAV for Category {} - impl ToEAV for Category { - fn to_eav(self) -> Entity { + impl From for Entity { + fn from(value: Category) -> Entity { Entity::default() .with_class("category") - .with_id(&self.id) - .with_attribute("label", self.label) + .with_id(&value.id) + .with_attribute("label", value.label) } } impl From for Category { @@ -64,14 +64,14 @@ mod tests { pub description: String, } impl EAV for Operation {} - impl ToEAV for Operation { - fn to_eav(self) -> Entity { + impl From for Entity { + fn from(value: Operation) -> Entity { Entity::default() .with_class("operation") - .with_id(&self.id) - .with_attribute("date", self.date) - .with_attribute("amount", self.amount) - .with_attribute("description", self.description) + .with_id(&value.id) + .with_attribute("date", value.date) + .with_attribute("amount", value.amount) + .with_attribute("description", value.description) } } impl From for Operation {