diff --git a/01.workspace/heave/src/str/catalog.rs b/01.workspace/heave/src/str/catalog.rs index 9005c4e..0103596 100644 --- a/01.workspace/heave/src/str/catalog.rs +++ b/01.workspace/heave/src/str/catalog.rs @@ -36,6 +36,24 @@ impl O { let entity = self.items.get(id); entity.map(|e| T::from(e.clone())) } + pub fn get_by_class_and_attribute( + &self, + class: &str, + attribute: &str, + value: impl Into + Clone, + ) -> Option + where + T: From, + { + let mut items = self + .items + .values() + .filter(|item| item.class == class) + .filter(|item| item.value_of(attribute) == Some(&value.clone().into())) + .take(1) + .map(|item| T::from(item.clone())); + items.next() + } pub fn list_by_class(&self, class: &str) -> Vec where T: From,