refactor: remove FromEAV trait in favor of From<Entity>
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -30,10 +30,10 @@ impl O {
|
||||
}
|
||||
pub fn get<T>(&self, id: &str) -> Option<T>
|
||||
where
|
||||
T: FromEAV,
|
||||
T: From<Entity>,
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -2,7 +2,7 @@ use crate::*;
|
||||
|
||||
/// TODO: INSERT DOCUMENTATION HERE
|
||||
pub trait T where
|
||||
Self: FromEAV,
|
||||
Self: From<Entity>,
|
||||
Self: ToEAV,
|
||||
{
|
||||
}
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
use crate::*;
|
||||
|
||||
pub trait T {
|
||||
fn from_eav(entity: Entity) -> Self;
|
||||
}
|
||||
@@ -1,3 +1,2 @@
|
||||
pub mod eav;
|
||||
pub mod from_eav;
|
||||
pub mod to_eav;
|
||||
|
||||
@@ -17,8 +17,8 @@ mod tests {
|
||||
.with_attribute("price", self.price)
|
||||
}
|
||||
}
|
||||
impl FromEAV for Product {
|
||||
fn from_eav(entity: Entity) -> Product {
|
||||
impl From<Entity> 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]
|
||||
|
||||
@@ -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<Entity> 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<Entity> 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<Entity> for Operation {
|
||||
fn from(entity: Entity) -> Self {
|
||||
Operation {
|
||||
id: entity.id.clone(),
|
||||
date: entity.unwrap("date"),
|
||||
|
||||
Reference in New Issue
Block a user