From b0d290407d3f51a3d68204364d94f231c407bcfa Mon Sep 17 00:00:00 2001 From: davidemazzocchi Date: Thu, 9 Oct 2025 15:11:54 +0200 Subject: [PATCH] review: make value_of internal and remove unused function --- 01.workspace/heave/src/str/entity.rs | 20 +------------------- 01.workspace/heave/src/tst/intended_use.rs | 9 +++------ 2 files changed, 4 insertions(+), 25 deletions(-) diff --git a/01.workspace/heave/src/str/entity.rs b/01.workspace/heave/src/str/entity.rs index 53e4376..04207c2 100644 --- a/01.workspace/heave/src/str/entity.rs +++ b/01.workspace/heave/src/str/entity.rs @@ -42,31 +42,13 @@ impl O { } self } - pub fn value_of(&self, id: &str) -> Option<&Value> { + pub(crate) fn value_of(&self, id: &str) -> Option<&Value> { let attribute = self.attributes.get(id); match attribute { None => None, Some(attribute) => Some(&attribute.value), } } - pub fn set(&mut self, id: &str, value: impl Into) -> Option { - let attribute = Attribute::new(id, value); - let previous_attribute = self.attributes.insert(attribute.id.clone(), attribute); - match previous_attribute { - None => None, - Some(attribute) => Some(attribute.value), - } - } - pub fn unset(&mut self, id: &str) -> Option { - let attribute = self.attributes.remove(id); - match attribute { - None => None, - Some(attribute) => Some(attribute.value), - } - } - pub fn has_attribute(&self, id: &str) -> bool { - self.attributes.contains_key(id) - } pub fn unwrap(&self, id: &str) -> T where T: From, diff --git a/01.workspace/heave/src/tst/intended_use.rs b/01.workspace/heave/src/tst/intended_use.rs index 5b6f313..f493f70 100644 --- a/01.workspace/heave/src/tst/intended_use.rs +++ b/01.workspace/heave/src/tst/intended_use.rs @@ -27,15 +27,12 @@ mod tests { } impl From for Entity { fn from(value: Product) -> Self { - let mut entity = Entity::new::() + Entity::new::() .with_id(&value.id) .with_attribute("name", value.name) .with_attribute("price", value.price) - .with_attribute("in_stock", value.in_stock); - if let Some(model) = value.model { - entity.set("model", model); - } - entity + .with_attribute("in_stock", value.in_stock) + .with_opt_attribute("model", value.model) } } #[test]