aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-05-08 15:48:54 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-08 15:48:54 +0800
commite875a80d52e5e44f107366cd4825936c44c824bb (patch)
tree0753be45a46c621771787b0abcaac9620e06ea8f /examples
parentd895af6e53eb4a18554b3174f819eb771e81ca05 (diff)
Add dispatch tree example and update doc version references
Diffstat (limited to 'examples')
-rw-r--r--examples/example-completion/src/main.rs2
-rw-r--r--examples/example-dispatch-tree/Cargo.lock115
-rw-r--r--examples/example-dispatch-tree/Cargo.toml7
-rw-r--r--examples/example-dispatch-tree/src/main.rs48
4 files changed, 171 insertions, 1 deletions
diff --git a/examples/example-completion/src/main.rs b/examples/example-completion/src/main.rs
index 7834db7..413afd3 100644
--- a/examples/example-completion/src/main.rs
+++ b/examples/example-completion/src/main.rs
@@ -3,7 +3,7 @@
//! # How to Deploy
//! 1. Enable the `comp` feature
//! ```toml
-//! mingling = { version = "0.1.5", features = [
+//! mingling = { version = "...", features = [
//! "comp", // Enable this feature
//! "parser"
//! ] }
diff --git a/examples/example-dispatch-tree/Cargo.lock b/examples/example-dispatch-tree/Cargo.lock
new file mode 100644
index 0000000..ed1c6f1
--- /dev/null
+++ b/examples/example-dispatch-tree/Cargo.lock
@@ -0,0 +1,115 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "example-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 = "just_template"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "db3edb658c34b10b69c4b3b58f7ba989cd09c82c0621dee1eef51843c2327225"
+dependencies = [
+ "just_fmt",
+]
+
+[[package]]
+name = "mingling"
+version = "0.1.8"
+dependencies = [
+ "mingling_core",
+ "mingling_macros",
+]
+
+[[package]]
+name = "mingling_core"
+version = "0.1.8"
+dependencies = [
+ "just_fmt",
+ "just_template",
+ "once_cell",
+ "thiserror",
+]
+
+[[package]]
+name = "mingling_macros"
+version = "0.1.8"
+dependencies = [
+ "just_fmt",
+ "once_cell",
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "once_cell"
+version = "1.21.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
+
+[[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.45"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
+dependencies = [
+ "proc-macro2",
+]
+
+[[package]]
+name = "syn"
+version = "2.0.117"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "unicode-ident",
+]
+
+[[package]]
+name = "thiserror"
+version = "2.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"
+dependencies = [
+ "thiserror-impl",
+]
+
+[[package]]
+name = "thiserror-impl"
+version = "2.0.18"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[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-dispatch-tree/Cargo.toml b/examples/example-dispatch-tree/Cargo.toml
new file mode 100644
index 0000000..f1c6785
--- /dev/null
+++ b/examples/example-dispatch-tree/Cargo.toml
@@ -0,0 +1,7 @@
+[package]
+name = "example-dispatch-tree"
+version = "0.1.0"
+edition = "2024"
+
+[dependencies]
+mingling = { path = "../../mingling", features = ["dispatch_tree", "comp"] }
diff --git a/examples/example-dispatch-tree/src/main.rs b/examples/example-dispatch-tree/src/main.rs
new file mode 100644
index 0000000..104f002
--- /dev/null
+++ b/examples/example-dispatch-tree/src/main.rs
@@ -0,0 +1,48 @@
+//! `Mingling` Example - Dispatch Tree
+//!
+//! # How to Deploy
+//! 1. Enable the `dispatch_tree` feature (`comp` is optional)
+//! ```toml
+//! mingling = { version = "...", features = [
+//! "dispatch_tree", // Enable this feature
+//! "comp" // optional
+//! ] }
+//! ```
+//!
+//! 2. Using `cargo expand`:
+//!
+//! ```bash
+//! cargo expand --manifest-path examples/example-dispatch-tree/Cargo.toml > expanded.rs
+//! cat expanded.rs | grep dispatch_args_trie -A 264
+//! ```
+
+#![allow(unused_mut)]
+
+use mingling::macros::{dispatcher, gen_program};
+
+fn main() {
+ let mut program = ThisProgram::new();
+
+ // After enabling `dispatch_tree`, this method will no longer exist
+ // program.with_dispatcher(CommandGreet);
+ //
+ // The `CompletionDispatcher` automatically generated by `comp` will also be imported
+ // automatically
+ // program.with_dispatcher(CompletionDispatcher);
+
+ program.exec();
+}
+
+dispatcher!("greet", CommandGreet => EntryGreet);
+dispatcher!("help", CommandHelp => EntryHelp);
+dispatcher!("quit", CommandQuit => EntryQuit);
+dispatcher!("list", CommandList => EntryList);
+dispatcher!("status", CommandStatus => EntryStatus);
+dispatcher!("save", CommandSave => EntrySave);
+dispatcher!("load", CommandLoad => EntryLoad);
+dispatcher!("config", CommandConfig => EntryConfig);
+dispatcher!("run", CommandRun => EntryRun);
+dispatcher!("debug", CommandDebug => EntryDebug);
+dispatcher!("version", CommandVersion => EntryVersion);
+
+gen_program!();