radix_engine/blueprints/models/
feature_set.rs

1use crate::internal_prelude::*;
2
3pub trait HasFeatures: Debug {
4    fn feature_names_str(&self) -> Vec<&'static str>;
5
6    fn feature_names_str_set(&self) -> IndexSet<&'static str> {
7        self.feature_names_str().into_iter().collect()
8    }
9
10    fn feature_names_string(&self) -> Vec<String> {
11        self.feature_names_str()
12            .into_iter()
13            .map(|s| s.to_owned())
14            .collect()
15    }
16
17    fn feature_names_string_set(&self) -> IndexSet<String> {
18        self.feature_names_str()
19            .into_iter()
20            .map(|s| s.to_owned())
21            .collect()
22    }
23}
24
25#[cfg(test)]
26mod tests {
27    use super::*;
28
29    #[derive(Debug)]
30    struct MyFeatures;
31
32    impl HasFeatures for MyFeatures {
33        fn feature_names_str(&self) -> Vec<&'static str> {
34            vec!["feature_1", "feature_2"]
35        }
36    }
37
38    #[test]
39    fn validate_feature_names_getters() {
40        let my_features = MyFeatures;
41
42        let idx_set = my_features.feature_names_str_set();
43        assert_eq!(idx_set.get_index_of("feature_1").unwrap(), 0);
44        assert_eq!(idx_set.get_index_of("feature_2").unwrap(), 1);
45
46        let v = my_features.feature_names_string();
47        assert_eq!(v[0], "feature_1");
48        assert_eq!(v[1], "feature_2");
49    }
50}