diff --git a/01.workspace/heave/src/str/entity.rs b/01.workspace/heave/src/str/entity.rs index 0dbe0d5..e1a57f0 100644 --- a/01.workspace/heave/src/str/entity.rs +++ b/01.workspace/heave/src/str/entity.rs @@ -12,9 +12,17 @@ impl O { Self { id: short_uuid::short!().to_string(), class: String::from(class), - attributes: std::collections::HashMap::new(), + ..Entity::default() } } + pub fn with_id(mut self, id: &str) -> Self { + self.id = id.to_string(); + self + } + pub fn with_class(mut self, class: &str) -> Self { + self.class = class.to_string(); + self + } pub fn with_attribute(mut self, id: &str, value: impl ToValue) -> Self { let attribute = Attribute::new(id, value); self.attributes.insert(attribute.id.clone(), attribute); diff --git a/01.workspace/heave/src/tst/intended_use.rs b/01.workspace/heave/src/tst/intended_use.rs index 688db0b..43082a4 100644 --- a/01.workspace/heave/src/tst/intended_use.rs +++ b/01.workspace/heave/src/tst/intended_use.rs @@ -3,12 +3,15 @@ mod tests { use crate::*; #[derive(Debug, Clone, PartialEq)] struct Product { + pub id: String, pub name: String, pub price: u64, } impl ToEAV for Product { fn to_eav(self) -> Entity { - Entity::new("product") + Entity::default() + .with_class("product") + .with_id(&self.id) .with_attribute("name", self.name) .with_attribute("price", self.price) } @@ -16,6 +19,7 @@ mod tests { impl FromEAV for Product { fn from_eav(entity: Entity) -> Product { Product { + id: entity.id.clone(), name: entity.unwrap("name"), price: entity.unwrap("price"), } @@ -108,6 +112,7 @@ mod tests { #[test] fn check_006() { let product = Product { + id: "abcdef".to_string(), name: "laptop".to_string(), price: 200000u64, };