diff --git a/01.workspace/heave/src/str/catalog.rs b/01.workspace/heave/src/str/catalog.rs index 26a6099..298a1ff 100644 --- a/01.workspace/heave/src/str/catalog.rs +++ b/01.workspace/heave/src/str/catalog.rs @@ -46,6 +46,24 @@ impl O { .collect(); items } + pub fn list_by_class_and_attribute( + &self, + class: &str, + attribute: &str, + value: impl Into + Clone, + ) -> Vec + where + T: From, + { + let items: Vec = self + .items + .values() + .filter(|item| item.class == class) + .filter(|item| item.value_of(attribute) == Some(&value.clone().into())) + .map(|item| T::from(item.clone())) + .collect(); + items + } pub fn persist(&self) { let path = path::Path::new(&self.path); sqlite::persist::catalog(path, self); diff --git a/01.workspace/heave/src/str/entity.rs b/01.workspace/heave/src/str/entity.rs index 979990e..a591282 100644 --- a/01.workspace/heave/src/str/entity.rs +++ b/01.workspace/heave/src/str/entity.rs @@ -59,7 +59,16 @@ impl O { where T: From, { - let value = self.value_of(id).unwrap(); - T::from(value.clone()) + self.value_of(id) + .map(|value| T::from(value.clone())) + .unwrap() + } + pub fn unwrap_or(&self, id: &str, default: T) -> T + where + T: From, + { + self.value_of(id) + .map(|value| T::from(value.clone())) + .unwrap_or(default) } }