From 6d0fb7c0f2fc9bf144b50b6bb00328b3f7057832 Mon Sep 17 00:00:00 2001 From: bigfoot547 Date: Mon, 13 Jan 2025 03:05:17 -0600 Subject: more stuff --- src/version.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'src/version.rs') diff --git a/src/version.rs b/src/version.rs index 078927d..ae91149 100644 --- a/src/version.rs +++ b/src/version.rs @@ -81,11 +81,24 @@ pub struct CompatibilityRule { pub os: Option } +pub trait FeatureMatcher { + fn matches(&self, feature: &str) -> bool; +} + +impl FeatureMatcher for F +where + F: Fn(&str) -> bool +{ + fn matches(&self, feature: &str) -> bool { + self(feature) + } +} + impl CompatibilityRule { - pub fn features_match(&self, checker: fn(&str) -> bool) -> bool { + pub fn features_match(&self, checker: impl FeatureMatcher) -> bool { if let Some(m) = self.features.as_ref() { for (feat, expect) in m { - if checker(feat) != *expect { + if checker.matches(feat) != *expect { return false; } } @@ -206,6 +219,16 @@ pub struct Library { pub url: Option // old format } +impl LibraryDownloads { + pub fn get_download_info(&self, classifier: Option<&str>) -> Option<&DownloadInfo> { + if let Some(classifier) = classifier { + self.classifiers.as_ref()?.get(classifier) + } else { + self.artifact.as_ref() + } + } +} + #[derive(Deserialize, Debug, Clone)] pub struct ClientLogging { pub argument: String, -- cgit v1.2.3-70-g09d2