| Crates.io | command_core |
| lib.rs | command_core |
| version | 0.1.1 |
| created_at | 2025-08-23 19:51:46.192298+00 |
| updated_at | 2025-08-23 23:33:02.875571+00 |
| description | A no_std flexible function interpreter using phf for compile-time command dispatch. |
| homepage | |
| repository | |
| max_upload_size | |
| id | 1807827 |
| size | 7,995 |
A minimal, #![no_std]-friendly function interpreter for mapping string commands to Rust functions using phf.
Designed for embedded systems, game engines, scripting layers, or any environment where you want fast, compile-time command dispatch without heap allocations.
#![no_std] compatible — works in embedded and constrained environments.phf for perfect hash maps at compile time.use command_core::{phf::phf_map, CommandFn, FI};
// Example state struct
struct MyStruct {}
// Example command function
fn print_cmd(_interpreter: &FI<MyStruct>, _state: &mut MyStruct, args: &[&str]) {
for arg in args {
println!("I have printed {}", arg);
}
}
// Compile-time command map
static FUNCTION_MAP: phf::Map<&'static str, CommandFn<MyStruct>> = phf_map! {
"print" => print_cmd,
};
fn main() {
let interpreter = FI::new(&FUNCTION_MAP);
let mut state = MyStruct {};
// Execute: print 37 47 57 67
interpreter.interpret(&["print", "37", "47", "57", "67"], &mut state);
}