From c425b63361841f81f2cb5a6dbe6c71fa7dd146d8 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Mon, 23 Mar 2026 01:46:31 +0100 Subject: [PATCH] refactor(exporters): single registry source of truth --- crates/exporters/src/lib.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) 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)]