activecube_rs/cube/
registry.rs1use std::collections::HashMap;
2use crate::cube::definition::CubeDefinition;
3
4#[derive(Debug, Clone)]
5pub struct CubeRegistry {
6 cubes: HashMap<String, CubeDefinition>,
7}
8
9impl CubeRegistry {
10 pub fn from_cubes(cubes: Vec<CubeDefinition>) -> Self {
11 let mut map = HashMap::new();
12 for cube in cubes {
13 map.insert(cube.name.clone(), cube);
14 }
15 tracing::info!(count = map.len(), "Cube registry initialized");
16 Self { cubes: map }
17 }
18
19 pub fn get(&self, name: &str) -> Option<&CubeDefinition> {
20 self.cubes.get(name)
21 }
22
23 pub fn cubes(&self) -> impl Iterator<Item = &CubeDefinition> {
24 self.cubes.values()
25 }
26
27 pub fn cube_names(&self) -> Vec<&str> {
28 self.cubes.keys().map(|s| s.as_str()).collect()
29 }
30}