Alternative to global const that can be built with a non-constant function
⚓ Rust 📅 2026-03-03 👤 surdeus 👁️ 4I would like to have:
const COMMANDS_XML: &str = include_str!("../../doc/commands.xml");
const commands_xml: CommandsXml = quick_xml::de::from_str(COMMANDS_XML).unwrap();
As written this does not compile because quick_xml::de::from_str is not a constant function.
I don't particuarly care about the performance difference between building the commands_xml structure at compile time or program startup.
My concern is that this structure is only used in the one file, so I would like to avoid needing to update main() to call an initialize function; as well as needing to pass this structure explicitly to all call points that might call into this module.
4 posts - 3 participants
🏷️ Rust_feed