reactive_graph_std_base/
providers.rs

1use reactive_graph_plugin_api::prelude::providers::*;
2
3/// Reads component type definitions from json or toml files.
4///
5/// Each component is defined in it's own file.
6/// The path is the location of the folder containing the files.
7///
8/// Implements trait TypeProvider<Components>
9#[derive(TypeProvider, Component)]
10#[type_provider(tys = "Components", path = "types/components")]
11pub struct BaseComponentsProvider {}
12
13#[cfg(test)]
14mod tests {
15    use super::*;
16    use reactive_graph_graph::ComponentTypeId;
17    use reactive_graph_graph::ComponentTypeIds;
18    use reactive_graph_plugin_api::TypeProvider;
19
20    #[test]
21    fn components_should_exist() {
22        let expected_tys = ComponentTypeIds::new()
23            .component(ComponentTypeId::new_from_type("base", "describable"))
24            .component(ComponentTypeId::new_from_type("base", "licensed"))
25            .component(ComponentTypeId::new_from_type("base", "named"))
26            .component(ComponentTypeId::new_from_type("base", "versioned"));
27        let component_provider = BaseComponentsProvider {};
28        let components = component_provider.get_types();
29        assert_eq!(expected_tys.len(), components.into_iter().filter(|(ty, _)| expected_tys.contains(ty)).count());
30    }
31}