feat: add utility function to set and unset an attribute from an entity

This commit is contained in:
2025-09-27 08:04:42 +02:00
parent 55e1b5d9cf
commit 01568e87c0

View File

@@ -25,4 +25,19 @@ impl O {
Some(attribute) => Some(&attribute.value),
}
}
pub fn set(&mut self, id: &str, value: Value) -> Option<Value> {
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<Value> {
let attribute = self.attributes.remove(id);
match attribute {
None => None,
Some(attribute) => Some(attribute.value),
}
}
}