refactor: remove FromEAV trait in favor of From<Entity>

This commit is contained in:
2025-09-30 07:08:37 +02:00
parent af860bdb22
commit 70c3b9108e
8 changed files with 12 additions and 25 deletions

View File

@@ -12,9 +12,7 @@ pub use crate::str::catalog::O as Catalog;
pub use crate::str::entity::O as Entity; pub use crate::str::entity::O as Entity;
pub use crate::str::value::E as Value; pub use crate::str::value::E as Value;
pub use crate::trt::eav::T as EAV; 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_eav::T as ToEAV;
// pub use crate::trt::to_value::T as ToValue;
mod sqlite { mod sqlite {
pub mod init { pub mod init {

View File

@@ -30,10 +30,10 @@ impl O {
} }
pub fn get<T>(&self, id: &str) -> Option<T> pub fn get<T>(&self, id: &str) -> Option<T>
where where
T: FromEAV, T: From<Entity>,
{ {
let entity = self.items.get(id); 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) { pub fn persist(&self) {
let path = path::Path::new(&self.path); let path = path::Path::new(&self.path);

View File

@@ -14,11 +14,6 @@ impl ToEAV for Entity {
self self
} }
} }
impl FromEAV for Entity {
fn from_eav(entity: Entity) -> Self {
entity
}
}
impl O { impl O {
pub fn new(class: &str) -> Self { pub fn new(class: &str) -> Self {

View File

@@ -2,7 +2,7 @@ use crate::*;
/// TODO: INSERT DOCUMENTATION HERE /// TODO: INSERT DOCUMENTATION HERE
pub trait T where pub trait T where
Self: FromEAV, Self: From<Entity>,
Self: ToEAV, Self: ToEAV,
{ {
} }

View File

@@ -1,5 +0,0 @@
use crate::*;
pub trait T {
fn from_eav(entity: Entity) -> Self;
}

View File

@@ -1,3 +1,2 @@
pub mod eav; pub mod eav;
pub mod from_eav;
pub mod to_eav; pub mod to_eav;

View File

@@ -17,8 +17,8 @@ mod tests {
.with_attribute("price", self.price) .with_attribute("price", self.price)
} }
} }
impl FromEAV for Product { impl From<Entity> for Product {
fn from_eav(entity: Entity) -> Product { fn from(entity: Entity) -> Self {
Product { Product {
id: entity.id.clone(), id: entity.id.clone(),
name: entity.unwrap("name"), name: entity.unwrap("name"),
@@ -119,7 +119,7 @@ mod tests {
}; };
let expected_product = product.clone(); let expected_product = product.clone();
let entity = product.to_eav(); let entity = product.to_eav();
let converted_product = Product::from_eav(entity); let converted_product = Product::from(entity);
assert_eq!(expected_product, converted_product); assert_eq!(expected_product, converted_product);
} }
#[test] #[test]

View File

@@ -21,8 +21,8 @@ mod tests {
.with_attribute("category_id", self.category_id) .with_attribute("category_id", self.category_id)
} }
} }
impl FromEAV for OperationToCategory { impl From<Entity> for OperationToCategory {
fn from_eav(entity: Entity) -> Self { fn from(entity: Entity) -> Self {
OperationToCategory { OperationToCategory {
id: entity.id.clone(), id: entity.id.clone(),
operation_id: entity.unwrap("operation_id"), operation_id: entity.unwrap("operation_id"),
@@ -46,8 +46,8 @@ mod tests {
.with_attribute("label", self.label) .with_attribute("label", self.label)
} }
} }
impl FromEAV for Category { impl From<Entity> for Category {
fn from_eav(entity: Entity) -> Self { fn from(entity: Entity) -> Self {
Category { Category {
id: entity.id.clone(), id: entity.id.clone(),
label: entity.unwrap("label"), label: entity.unwrap("label"),
@@ -74,8 +74,8 @@ mod tests {
.with_attribute("description", self.description) .with_attribute("description", self.description)
} }
} }
impl FromEAV for Operation { impl From<Entity> for Operation {
fn from_eav(entity: Entity) -> Self { fn from(entity: Entity) -> Self {
Operation { Operation {
id: entity.id.clone(), id: entity.id.clone(),
date: entity.unwrap("date"), date: entity.unwrap("date"),