reactive_graph_std_base_model/component/
licensed.rs

1use license::License;
2
3use crate::NAMESPACE_BASE;
4use reactive_graph_graph::component_model;
5use reactive_graph_graph::component_ty;
6use reactive_graph_graph::properties;
7
8properties!(LicensedProperties, (LICENSE, "license", ""), (ATTRIBUTION, "attribution", ""));
9
10component_ty!(COMPONENT_LICENSED, NAMESPACE_BASE, COMPONENT_NAME_LICENSED, "licensed");
11
12component_model!(
13    Licensed,
14    data license string,
15    data attribution string,
16);
17
18pub trait SPDXLicensed: Licensed {
19    fn set_license_checked(&self, license: &str) {
20        if let Ok(license) = license.parse::<&dyn License>() {
21            self.set_license(license.id());
22        }
23    }
24
25    fn to_license(&self) -> Option<&dyn License> {
26        self.get_license().and_then(|license| license.parse::<&dyn License>().ok())
27    }
28
29    fn is_osi_approved(&self) -> bool {
30        self.get_license()
31            .and_then(|license| license.parse::<&dyn License>().ok())
32            .map(|license| license.is_osi_approved())
33            .unwrap_or(false)
34    }
35
36    fn is_deprecated(&self) -> bool {
37        self.get_license()
38            .and_then(|license| license.parse::<&dyn License>().ok())
39            .map(|license| license.is_deprecated())
40            .unwrap_or(false)
41    }
42}