aboutsummaryrefslogtreecommitdiff
path: root/examples/example-combine-pathf-dispatch-tree/src
diff options
context:
space:
mode:
Diffstat (limited to 'examples/example-combine-pathf-dispatch-tree/src')
-rw-r--r--examples/example-combine-pathf-dispatch-tree/src/main.rs31
-rw-r--r--examples/example-combine-pathf-dispatch-tree/src/sub/mod.rs22
2 files changed, 53 insertions, 0 deletions
diff --git a/examples/example-combine-pathf-dispatch-tree/src/main.rs b/examples/example-combine-pathf-dispatch-tree/src/main.rs
new file mode 100644
index 0000000..98b3e4c
--- /dev/null
+++ b/examples/example-combine-pathf-dispatch-tree/src/main.rs
@@ -0,0 +1,31 @@
+//! Example: Combining pathf + dispatch_tree
+//!
+//! > This example demonstrates how to use `pathf` and `dispatch_tree` together.
+//! > Types are defined in a submodule (`sub`), and `gen_program!()` resolves
+//! > them automatically via pathf without explicit `use` imports.
+//! >
+//! > **Important**: `dispatch_tree` must be enabled in BOTH `[dependencies]`
+//! > AND `[build-dependencies]` so that pathf's builder can detect
+//! > `__internal_dispatcher_*` types needed by the dispatch tree.
+//! >
+//! > Also requires `extra_macros` for the implicit `dispatcher!("hello")` form.
+//!
+//! Run:
+//! ```bash
+//! cargo run --manifest-path examples/example-combine-pathf-dispatch-tree/Cargo.toml --quiet -- hello Alice
+//! ```
+//!
+//! Output:
+//! ```plaintext
+//! Hello, Alice!
+//! ```
+
+mod sub;
+
+use mingling::macros::gen_program;
+
+fn main() {
+ ThisProgram::new().exec_and_exit();
+}
+
+gen_program!();
diff --git a/examples/example-combine-pathf-dispatch-tree/src/sub/mod.rs b/examples/example-combine-pathf-dispatch-tree/src/sub/mod.rs
new file mode 100644
index 0000000..e0b7743
--- /dev/null
+++ b/examples/example-combine-pathf-dispatch-tree/src/sub/mod.rs
@@ -0,0 +1,22 @@
+use crate::Next;
+use mingling::{macros::r_println, prelude::*};
+
+dispatcher!("hello");
+
+pack!(ResultMessage = String);
+
+#[chain]
+pub fn handle_my(args: EntryHello) -> Next {
+ let name: ResultMessage = args
+ .inner
+ .first()
+ .cloned()
+ .unwrap_or_else(|| "World".to_string())
+ .into();
+ name
+}
+
+#[renderer]
+pub fn render_my(msg: ResultMessage) {
+ r_println!("Hello, {}!", *msg);
+}