command_core

Crates.iocommand_core
lib.rscommand_core
version0.1.1
created_at2025-08-23 19:51:46.192298+00
updated_at2025-08-23 23:33:02.875571+00
descriptionA no_std flexible function interpreter using phf for compile-time command dispatch.
homepage
repository
max_upload_size
id1807827
size7,995
(WebAppEnjoyer)

documentation

README

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);
}
Commit count: 0

cargo fmt