From 01568e87c00d12d614e906215b0198883dd3c12b Mon Sep 17 00:00:00 2001 From: davidemazzocchi Date: Sat, 27 Sep 2025 08:04:42 +0200 Subject: [PATCH] feat: add utility function to set and unset an attribute from an entity --- 01.workspace/heave/src/str/entity.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/01.workspace/heave/src/str/entity.rs b/01.workspace/heave/src/str/entity.rs index 5eb8609..13e3ff5 100644 --- a/01.workspace/heave/src/str/entity.rs +++ b/01.workspace/heave/src/str/entity.rs @@ -25,4 +25,19 @@ impl O { Some(attribute) => Some(&attribute.value), } } + pub fn set(&mut self, id: &str, value: Value) -> 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), + } + } }