diff --git a/crates/exporters/src/lib.rs b/crates/exporters/src/lib.rs index e4c2888..c91ce40 100644 --- a/crates/exporters/src/lib.rs +++ b/crates/exporters/src/lib.rs @@ -6,16 +6,21 @@ use lib::{BlockPalette, StructureExporter}; pub use litematica::LitematicaExporter; pub use mcfunction::McFunctionExporter; -pub fn available_names() -> &'static [&'static str] { - &["mcfunction", "litematica"] +type ExporterFactory = fn(&BlockPalette) -> Box; + +const REGISTRY: &[(&str, ExporterFactory)] = &[ + ("mcfunction", |p| Box::new(McFunctionExporter::new(p))), + ("litematica", |p| Box::new(LitematicaExporter::new(p))), +]; + +pub fn available_names() -> Vec<&'static str> { + REGISTRY.iter().map(|(name, _)| *name).collect() } pub fn build(name: &str, palette: &BlockPalette) -> Option> { - match name { - "mcfunction" => Some(Box::new(McFunctionExporter::new(palette))), - "litematica" => Some(Box::new(LitematicaExporter::new(palette))), - _ => None, - } + REGISTRY.iter() + .find(|(n, _)| *n == name) + .map(|(_, factory)| factory(palette)) } #[cfg(test)]