diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-28 09:18:17 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-28 09:18:17 +0800 |
| commit | 86bc9000c5687db6434a5d20f409dda8b1d7a43a (patch) | |
| tree | c28cb62dee7ad1a81abf9345e16b725866fbce7a /examples/example-pathfinder/src | |
| parent | 748c14588cf1c31c8b8d60a9c94349c0173ef607 (diff) | |
feat(docs): add Module Pathfinder example for the `pathf` feature
Diffstat (limited to 'examples/example-pathfinder/src')
| -rw-r--r-- | examples/example-pathfinder/src/main.rs | 30 | ||||
| -rw-r--r-- | examples/example-pathfinder/src/sub/mod.rs | 21 |
2 files changed, 51 insertions, 0 deletions
diff --git a/examples/example-pathfinder/src/main.rs b/examples/example-pathfinder/src/main.rs new file mode 100644 index 0000000..0f93a8d --- /dev/null +++ b/examples/example-pathfinder/src/main.rs @@ -0,0 +1,30 @@ +//! Example: Module Pathfinder (pathf) +//! +//! > This example demonstrates how to use the `pathf` feature to define types +//! > in submodules without needing explicit `use` in the main module. +//! > All type paths are resolved automatically at build time. +//! +//! Run: +//! ```bash +//! cargo run --manifest-path examples/example-pathfinder/Cargo.toml --quiet -- greet +//! cargo run --manifest-path examples/example-pathfinder/Cargo.toml --quiet -- greet Alice +//! ``` +//! +//! Output: +//! ```plaintext +//! Hello, World! +//! Hello, Alice! +//! ``` + +mod sub; + +use mingling::macros::gen_program; +use crate::sub::CMDGreet; + +fn main() { + let mut program = ThisProgram::new(); + program.with_dispatcher(CMDGreet); + program.exec_and_exit(); +} + +gen_program!(); diff --git a/examples/example-pathfinder/src/sub/mod.rs b/examples/example-pathfinder/src/sub/mod.rs new file mode 100644 index 0000000..ef10a75 --- /dev/null +++ b/examples/example-pathfinder/src/sub/mod.rs @@ -0,0 +1,21 @@ +use mingling::prelude::*; +use crate::Next; + +dispatcher!("greet", CMDGreet => EntryGreet); +pack!(ResultName = String); + +#[chain] +pub fn handle_greet(args: EntryGreet) -> Next { + let name: ResultName = args + .inner + .first() + .cloned() + .unwrap_or_else(|| "World".to_string()) + .into(); + name +} + +#[renderer] +pub fn render_name(name: ResultName) { + r_println!("Hello, {}!", *name); +} |
