command_core 0.1.1

A no_std flexible function interpreter using phf for compile-time command dispatch.
Documentation
  • Coverage
  • 80%
    4 out of 5 items documented0 out of 3 items with examples
  • Size
  • Source code size: 7.49 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 718.08 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • WebAppEnjoyer

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 phf for 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);
}