From 4588e17f7ddacd8391a5c881a209735e08d48797 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Tue, 4 Aug 2026 13:26:48 +0800 Subject: feat: add entry metadata system with compile-time typed values Add `Metadata` trait and `#[metadata(Entry)]` attribute macro to attach arbitrary, compile-time-typed metadata to entries. Implement `ProgramCollect::get_metadata()` for runtime retrieval, backed by a global registry populated by `register_metadata!`. Extend `pathf` with `MetadataPattern` to resolve metadata types across modules at build time. Add two examples demonstrating metadata usage with and without pathf integration. --- .../example-combine-pathf-metadata/src/main.rs | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 examples/example-combine-pathf-metadata/src/main.rs (limited to 'examples/example-combine-pathf-metadata/src/main.rs') diff --git a/examples/example-combine-pathf-metadata/src/main.rs b/examples/example-combine-pathf-metadata/src/main.rs new file mode 100644 index 0000000..a68eac5 --- /dev/null +++ b/examples/example-combine-pathf-metadata/src/main.rs @@ -0,0 +1,33 @@ +//! Example: Combining pathf + entry metadata +//! +//! > Demonstrates combining the `pathf` feature with entry metadata. The metadata +//! > `DataType` (`Description`) and the dispatchers/entries are defined in the `sub` +//! > module. Thanks to `pathf`, `gen_program!()` resolves these types across +//! > modules automatically, so `main` stays minimal. +//! +//! Run: +//! ```bash +//! cargo run --manifest-path examples/example-combine-pathf-metadata/Cargo.toml --quiet -- hello Alice +//! cargo run --manifest-path examples/example-combine-pathf-metadata/Cargo.toml --quiet -- hello +//! cargo run --manifest-path examples/example-combine-pathf-metadata/Cargo.toml --quiet -- desc +//! ``` +//! +//! Output: +//! ```plaintext +//! Hello, Alice! +//! Hello, World! +//! EntryHello desc = okay +//! ``` + +mod sub; + +use mingling::prelude::*; + +fn main() { + let mut program = ThisProgram::new(); + program.with_dispatcher(sub::CMDHello); + program.with_dispatcher(sub::CMDDescription); + program.exec_and_exit(); +} + +gen_program!(); -- cgit