aboutsummaryrefslogtreecommitdiff
path: root/examples/example-combine-pathf-dispatch-tree
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-29 15:10:11 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-29 15:10:57 +0800
commit709b672731bcc1b68209cadc38e0de78d7c28c03 (patch)
tree0e5d8fa7b77a52b9a51ecbd5476e33f2e93274ec /examples/example-combine-pathf-dispatch-tree
parentdc05173f3eafe0e782bc8824581c3819c8688782 (diff)
feat(examples): add pathf + dispatch tree combination example
Diffstat (limited to 'examples/example-combine-pathf-dispatch-tree')
-rw-r--r--examples/example-combine-pathf-dispatch-tree/Cargo.lock85
-rw-r--r--examples/example-combine-pathf-dispatch-tree/Cargo.toml26
-rw-r--r--examples/example-combine-pathf-dispatch-tree/build.rs3
-rw-r--r--examples/example-combine-pathf-dispatch-tree/page.toml10
-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
6 files changed, 177 insertions, 0 deletions
diff --git a/examples/example-combine-pathf-dispatch-tree/Cargo.lock b/examples/example-combine-pathf-dispatch-tree/Cargo.lock
new file mode 100644
index 0000000..4d3e64a
--- /dev/null
+++ b/examples/example-combine-pathf-dispatch-tree/Cargo.lock
@@ -0,0 +1,85 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "example-combine-pathf-dispatch-tree"
+version = "0.1.0"
+dependencies = [
+ "mingling",
+]
+
+[[package]]
+name = "just_fmt"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5454cda0d57db59778608d7a47bff5b16c6705598265869fb052b657f66cf05e"
+
+[[package]]
+name = "mingling"
+version = "0.2.0"
+dependencies = [
+ "mingling_core",
+ "mingling_macros",
+]
+
+[[package]]
+name = "mingling_core"
+version = "0.2.0"
+dependencies = [
+ "just_fmt",
+ "mingling_pathf",
+]
+
+[[package]]
+name = "mingling_macros"
+version = "0.2.0"
+dependencies = [
+ "just_fmt",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "mingling_pathf"
+version = "0.2.0"
+dependencies = [
+ "proc-macro2",
+ "syn",
+]
+
+[[package]]
+name = "proc-macro2"
+version = "1.0.106"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
+dependencies = [
+ "unicode-ident",
+]
+
+[[package]]
+name = "quote"
+version = "1.0.46"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "dfbc457d0c7a0759a614551b11a6409e5951f6c7537be1f1b7682b9ae9230368"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "syn"
+version = "2.0.118"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1b9ae57f904213ebb649ce6895b8a66c66f0203b9319718f69a5612a065b1422"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "unicode-ident"
+version = "1.0.24"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
diff --git a/examples/example-combine-pathf-dispatch-tree/Cargo.toml b/examples/example-combine-pathf-dispatch-tree/Cargo.toml
new file mode 100644
index 0000000..862c5ac
--- /dev/null
+++ b/examples/example-combine-pathf-dispatch-tree/Cargo.toml
@@ -0,0 +1,26 @@
+[package]
+name = "example-combine-pathf-dispatch-tree"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
+mingling = { path = "../../mingling", features = [
+ "dispatch_tree",
+ "extra_macros",
+ "pathf",
+] }
+
+[build-dependencies]
+mingling = { path = "../../mingling", features = [
+ "builds",
+
+ # --------- IMPORTANT ---------
+ # To use pathf under dispatch_tree
+ # **must** enable the `dispatch_tree`
+ # feature in build dependencies
+ "dispatch_tree",
+ "pathf",
+ # --------- IMPORTANT ---------
+] }
+
+[workspace]
diff --git a/examples/example-combine-pathf-dispatch-tree/build.rs b/examples/example-combine-pathf-dispatch-tree/build.rs
new file mode 100644
index 0000000..4c66258
--- /dev/null
+++ b/examples/example-combine-pathf-dispatch-tree/build.rs
@@ -0,0 +1,3 @@
+fn main() {
+ mingling::pathf::analyze_and_build_type_mapping().unwrap();
+}
diff --git a/examples/example-combine-pathf-dispatch-tree/page.toml b/examples/example-combine-pathf-dispatch-tree/page.toml
new file mode 100644
index 0000000..e8f32f2
--- /dev/null
+++ b/examples/example-combine-pathf-dispatch-tree/page.toml
@@ -0,0 +1,10 @@
+[example]
+id = "example-combine-pathf-dispatch-tree"
+name = "Pathfinder + Dispatch Tree"
+icon = "🧭"
+category = "advanced"
+desc = """
+Demonstrates combining the `pathf` and `dispatch_tree` features. Types are defined in submodules and automatically resolved. Requires `dispatch_tree` in both `[dependencies]` and `[build-dependencies]`.
+"""
+tags = ["pathf", "dispatch_tree", "extra_macros", "build.rs"]
+files = ["src/main.rs", "src/sub/mod.rs", "build.rs", "Cargo.toml"]
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);
+}