From 70c3b9108e9073d384e6a8bd70da7a12ee0d9ded Mon Sep 17 00:00:00 2001 From: davidemazzocchi Date: Tue, 30 Sep 2025 07:08:37 +0200 Subject: [PATCH] refactor: remove FromEAV trait in favor of From --- 01.workspace/heave/src/lib.rs | 2 -- 01.workspace/heave/src/str/catalog.rs | 4 ++-- 01.workspace/heave/src/str/entity.rs | 5 ----- 01.workspace/heave/src/trt/eav.rs | 2 +- 01.workspace/heave/src/trt/from_eav.rs | 5 ----- 01.workspace/heave/src/trt/mod.rs | 1 - 01.workspace/heave/src/tst/intended_use.rs | 6 +++--- 01.workspace/heave/src/tst/rusty_budger_use.rs | 12 ++++++------ 8 files changed, 12 insertions(+), 25 deletions(-) delete mode 100644 01.workspace/heave/src/trt/from_eav.rs diff --git a/01.workspace/heave/src/lib.rs b/01.workspace/heave/src/lib.rs index 940a7a6..130d69c 100644 --- a/01.workspace/heave/src/lib.rs +++ b/01.workspace/heave/src/lib.rs @@ -12,9 +12,7 @@ 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::from_eav::T as FromEAV; pub use crate::trt::to_eav::T as ToEAV; -// pub use crate::trt::to_value::T as ToValue; mod sqlite { pub mod init { diff --git a/01.workspace/heave/src/str/catalog.rs b/01.workspace/heave/src/str/catalog.rs index 654883e..ffdd47b 100644 --- a/01.workspace/heave/src/str/catalog.rs +++ b/01.workspace/heave/src/str/catalog.rs @@ -30,10 +30,10 @@ impl O { } pub fn get(&self, id: &str) -> Option where - T: FromEAV, + T: From, { let entity = self.items.get(id); - entity.map(|e| T::from_eav(e.clone())) + entity.map(|e| T::from(e.clone())) } pub fn persist(&self) { let path = path::Path::new(&self.path); diff --git a/01.workspace/heave/src/str/entity.rs b/01.workspace/heave/src/str/entity.rs index 5e05104..1939169 100644 --- a/01.workspace/heave/src/str/entity.rs +++ b/01.workspace/heave/src/str/entity.rs @@ -14,11 +14,6 @@ impl ToEAV for Entity { self } } -impl FromEAV for Entity { - fn from_eav(entity: Entity) -> Self { - entity - } -} impl O { pub fn new(class: &str) -> Self { diff --git a/01.workspace/heave/src/trt/eav.rs b/01.workspace/heave/src/trt/eav.rs index 55d0a5d..68d588a 100644 --- a/01.workspace/heave/src/trt/eav.rs +++ b/01.workspace/heave/src/trt/eav.rs @@ -2,7 +2,7 @@ use crate::*; /// TODO: INSERT DOCUMENTATION HERE pub trait T where - Self: FromEAV, + Self: From, Self: ToEAV, { } diff --git a/01.workspace/heave/src/trt/from_eav.rs b/01.workspace/heave/src/trt/from_eav.rs deleted file mode 100644 index 3b5335a..0000000 --- a/01.workspace/heave/src/trt/from_eav.rs +++ /dev/null @@ -1,5 +0,0 @@ -use crate::*; - -pub trait T { - fn from_eav(entity: Entity) -> Self; -} diff --git a/01.workspace/heave/src/trt/mod.rs b/01.workspace/heave/src/trt/mod.rs index 3dbacd0..de7e67e 100644 --- a/01.workspace/heave/src/trt/mod.rs +++ b/01.workspace/heave/src/trt/mod.rs @@ -1,3 +1,2 @@ pub mod eav; -pub mod from_eav; pub mod to_eav; diff --git a/01.workspace/heave/src/tst/intended_use.rs b/01.workspace/heave/src/tst/intended_use.rs index 7bb8008..6b7a84a 100644 --- a/01.workspace/heave/src/tst/intended_use.rs +++ b/01.workspace/heave/src/tst/intended_use.rs @@ -17,8 +17,8 @@ mod tests { .with_attribute("price", self.price) } } - impl FromEAV for Product { - fn from_eav(entity: Entity) -> Product { + impl From for Product { + fn from(entity: Entity) -> Self { Product { id: entity.id.clone(), name: entity.unwrap("name"), @@ -119,7 +119,7 @@ mod tests { }; let expected_product = product.clone(); let entity = product.to_eav(); - let converted_product = Product::from_eav(entity); + let converted_product = Product::from(entity); assert_eq!(expected_product, converted_product); } #[test] diff --git a/01.workspace/heave/src/tst/rusty_budger_use.rs b/01.workspace/heave/src/tst/rusty_budger_use.rs index 680b437..baff53f 100644 --- a/01.workspace/heave/src/tst/rusty_budger_use.rs +++ b/01.workspace/heave/src/tst/rusty_budger_use.rs @@ -21,8 +21,8 @@ mod tests { .with_attribute("category_id", self.category_id) } } - impl FromEAV for OperationToCategory { - fn from_eav(entity: Entity) -> Self { + impl From for OperationToCategory { + fn from(entity: Entity) -> Self { OperationToCategory { id: entity.id.clone(), operation_id: entity.unwrap("operation_id"), @@ -46,8 +46,8 @@ mod tests { .with_attribute("label", self.label) } } - impl FromEAV for Category { - fn from_eav(entity: Entity) -> Self { + impl From for Category { + fn from(entity: Entity) -> Self { Category { id: entity.id.clone(), label: entity.unwrap("label"), @@ -74,8 +74,8 @@ mod tests { .with_attribute("description", self.description) } } - impl FromEAV for Operation { - fn from_eav(entity: Entity) -> Self { + impl From for Operation { + fn from(entity: Entity) -> Self { Operation { id: entity.id.clone(), date: entity.unwrap("date"),