aboutsummaryrefslogtreecommitdiff
path: root/docs/pages/9-error-handling.md
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-17 05:49:19 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-17 05:49:19 +0800
commit57c53affe3542cb6bd4e79ee4c18f20a1bd76b2d (patch)
tree1cd4aef44cb7a45a8cd9d520b598f5f181e24c76 /docs/pages/9-error-handling.md
parentef23cd944402939605c78a4a853ef6e33af02c21 (diff)
refactor!: replace pack! macros with derive-based pipeline types
Remove the `pack!`, `pack_err!`, `pack_structural!`, and `pack_err_structural!` macros, replacing all pipeline type definitions with `#[derive(Grouped)]` and `#[derive(Grouped, Wrap)]` attributes. This changes the generated struct shape from named-field structs with an `inner` field to tuple structs accessed via `.0`, and removes the auto-generated `name` and `info` fields from error types.
Diffstat (limited to 'docs/pages/9-error-handling.md')
-rw-r--r--docs/pages/9-error-handling.md40
1 files changed, 23 insertions, 17 deletions
diff --git a/docs/pages/9-error-handling.md b/docs/pages/9-error-handling.md
index eefc0f0..0cacf01 100644
--- a/docs/pages/9-error-handling.md
+++ b/docs/pages/9-error-handling.md
@@ -20,17 +20,19 @@ Error values can also take either path—you can render the error msg directly,
```rust
@@@dispatcher!("greet", EntryGreet);
-pack!(ResultGreeting = String);
-pack!(ErrorNameEmpty = String);
+#[derive(Grouped, Wrap)]
+pub struct ResultGreeting(String);
+#[derive(Grouped, Wrap)]
+pub struct ErrorNameEmpty(String);
#[chain]
fn handle_greet(args: EntryGreet) -> Next {
- let name = args.inner.first().cloned().unwrap_or_default();
+ let name = args.0.first().cloned().unwrap_or_default();
if name.is_empty() {
- ErrorNameEmpty::new("name is required".to_string()).to_render()
+ ErrorNameEmpty("name is required".to_string()).to_render()
} else {
- ResultGreeting::new(name).to_render()
+ ResultGreeting(name).to_render()
}
}
```
@@ -40,9 +42,11 @@ Then write separate Renderers:
```rust
@@@use mingling::macros::buffer;
@@@dispatcher!("greet", EntryGreet);
-@@@pack!(ResultGreeting = String);
-@@@pack!(ErrorNameEmpty = String);
-@@@#[chain] fn handle_greet(args: EntryGreet) -> Next { ResultGreeting::new(args.inner.first().cloned().unwrap_or_default()).to_render() }
+@@@#[derive(Grouped, Wrap)]
+@@@pub struct ResultGreeting(String);
+@@@#[derive(Grouped, Wrap)]
+@@@pub struct ErrorNameEmpty(String);
+@@@#[chain] fn handle_greet(args: EntryGreet) -> Next { ResultGreeting(args.0.first().cloned().unwrap_or_default()).to_render() }
#[renderer(buffer)]
fn render_greet(result: ResultGreeting) {
@@ -63,16 +67,18 @@ Each Renderer does its own job; what the user sees depends on what the Chain ret
@@@use mingling::macros::buffer;
dispatcher!("greet", EntryGreet);
-pack!(ResultGreeting = String);
-pack!(ErrorNameEmpty = String);
+#[derive(Grouped, Wrap)]
+pub struct ResultGreeting(String);
+#[derive(Grouped, Wrap)]
+pub struct ErrorNameEmpty(String);
#[chain]
fn handle_greet(args: EntryGreet) -> Next {
- let name = args.inner.first().cloned().unwrap_or_default();
+ let name = args.0.first().cloned().unwrap_or_default();
if name.is_empty() {
- ErrorNameEmpty::new("name is required".to_string()).to_render()
+ ErrorNameEmpty("name is required".to_string()).to_render()
} else {
- ResultGreeting::new(name).to_render()
+ ResultGreeting(name).to_render()
}
}
@@ -104,14 +110,14 @@ Hello, Alice!
Error: name is required
```
-## About `pack_err!`
+## Declaring Error Types
-If you've enabled `extras`, you can use `pack_err!` to quickly declare an error type with an auto-generated `name` field:
+You can use `#[derive(Grouped, Default)]` to quickly declare an error type with no payload:
```rust
// Features: ["extras"]
-pack_err!(ErrorNotFound);
-// Generates: struct ErrorNotFound { pub name: String }
+#[derive(Grouped, Default)]
+pub struct ErrorNotFound;
```
See [Feature List](pages/other/features) for details.