dispatch-core
dispatch-core is a small, allocation-free dispatcher designed for no_std
environments. It selects the first matching item from a table and runs it
through explicit before/after middleware hooks.
The crate deliberately does not own application state. A higher-level crate
can build a state machine on top by dispatching (state, event) inputs and
committing the returned next state only after dispatch succeeds.
Installation
Add the crate to your project:
[]
= "0.1.0"
Execution model
For each call, the dispatcher:
- selects the first matching table item;
- runs the middleware's
beforehook; - invokes the selected handler;
- runs the middleware's
afterhook.
Processing stops at the first error. Middleware receives an immutable input,
so it cannot invalidate a match after selection. The after hook can modify a
successful output.
Example
use Infallible;
use ;
;
let routes = ;
let mut dispatcher = new;
assert_eq!;
Embedded build
The repository includes a convenience command for Cortex-M0 targets:
cargo build-thumbv6m
Normal cargo build, cargo test, and cargo clippy commands use the host
target, so the test harness remains available.
Complete example
See examples/command_dispatch.rs for a
complete command-routing example with authorization before the handler and
output auditing after it succeeds. Run it with:
cargo run --example command_dispatch
Minimum supported Rust version
dispatch-core requires Rust 1.85 or newer because it uses the Rust 2024
edition.
License
Licensed under either of the following, at your option:
- Apache License, Version 2.0 (LICENSE-APACHE);
- MIT License (LICENSE-MIT).
AI authorship disclosure
The current public-release implementation, tests, example, documentation, and release configuration were generated by OpenAI Codex under the repository owner's direction. They should not be represented as handwritten human work. See AI_DISCLOSURE.md for the exact scope.