aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/mozart-registry/src/installed.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/mozart-registry/src/installed.rs')
-rw-r--r--crates/mozart-registry/src/installed.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/crates/mozart-registry/src/installed.rs b/crates/mozart-registry/src/installed.rs
index da02c6a..108b844 100644
--- a/crates/mozart-registry/src/installed.rs
+++ b/crates/mozart-registry/src/installed.rs
@@ -1,3 +1,4 @@
+use mozart_core::installer::HasSuggests;
use mozart_core::package::to_json_pretty;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
@@ -58,6 +59,24 @@ pub struct InstalledPackageEntry {
pub extra_fields: BTreeMap<String, serde_json::Value>,
}
+impl HasSuggests for InstalledPackageEntry {
+ fn pretty_name(&self) -> &str {
+ &self.name
+ }
+
+ fn suggests(&self) -> Vec<(String, String)> {
+ let Some(val) = self.extra_fields.get("suggest") else {
+ return Vec::new();
+ };
+ let Some(obj) = val.as_object() else {
+ return Vec::new();
+ };
+ obj.iter()
+ .filter_map(|(target, reason)| reason.as_str().map(|r| (target.clone(), r.to_string())))
+ .collect()
+ }
+}
+
impl Default for InstalledPackages {
fn default() -> Self {
Self::new()