diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-20 01:58:41 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-20 02:06:08 +0800 |
| commit | 90f563d7bbcbea98ee966bfb62a3e4a942e19c64 (patch) | |
| tree | fb4f81f4c06d4d4f0c2a41f6c2fdc97682dec462 /docs/pages/other/features.md | |
| parent | fcfe66875f46e8652170fd190416d796ae30aabc (diff) | |
Document `group!` and `pack_err!` macros for extra macros feature
Diffstat (limited to 'docs/pages/other/features.md')
| -rw-r--r-- | docs/pages/other/features.md | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/docs/pages/other/features.md b/docs/pages/other/features.md index f0edc84..6e2a364 100644 --- a/docs/pages/other/features.md +++ b/docs/pages/other/features.md @@ -96,6 +96,8 @@ For example, allows the shorthand form `dispatcher!("greet")`, which auto-genera |---|---| | `empty_result!()` | Shorthand for returning an empty result early in a chain | | `entry!(Type, ["a", "b"])` | Construct test data for an entry type | +| `group!(Type)` | Register external types as group members without modifying them | +| `pack_err!(ErrorType)` / `pack_err!(ErrorType = Inner)` | Create error types with an automatic `name` field | | `#[program_setup]` | Declare a program initialization function | | `dispatcher!("cmd.path")` **shorthand** | Omit `CMDStruct => EntryStruct`, names are auto-derived | @@ -167,6 +169,43 @@ fn main() { fn handle_hello(args: EntryHello) {} ``` +### `group!` + +Registers an external type as a member of the program group without modifying its definition. +The type's simple name is used as the enum variant, just like `pack!` or `#[derive(Groupped)]`. + +```rust +// Features: ["extra_macros"] +use mingling::macros::group; +use std::num::ParseIntError; + +// Register std::num::ParseIntError as a group member. +// After this, ParseIntError can be used in #[chain] and #[renderer] functions. +group!(std::num::ParseIntError); +``` + +### `pack_err!` + +Creates an error struct with an automatic `name: String` field set to the snake_case +of the struct name. Optionally wraps an inner type for additional context. + +```rust +// Features: ["extra_macros"] +use std::path::PathBuf; + +// Simple form — only a name field: +pack_err!(ErrorNotFound); +// Generates: +// struct ErrorNotFound { pub name: String } +// impl Default for ErrorNotFound { ... } + +// Typed form — with additional info field: +pack_err!(ErrorNotDir = PathBuf); +// Generates: +// struct ErrorNotDir { pub name: String, pub info: PathBuf } +// impl ErrorNotDir { pub fn new(info: PathBuf) -> Self { ... } } +``` + </details> ## Feature `general_renderer` |
