2 releases
Uses new Rust 2024
| 0.1.1 | Aug 23, 2025 |
|---|---|
| 0.1.0 | Aug 23, 2025 |
#2014 in Embedded development
5KB
command_core
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.
Features
#![no_std]compatible — works in embedded and constrained environments.- Zero runtime hashing — powered by
phffor perfect hash maps at compile time. - Immutable interpreter reference — allows recursive commands or conditional logic.
- Type-safe command functions — no dynamic typing or unsafe casting.
Example
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);
}
Dependencies
~305–730KB
~17K SLoC