From 57c53affe3542cb6bd4e79ee4c18f20a1bd76b2d Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 17 Aug 2026 05:49:19 +0800 Subject: 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. --- examples/example-error-handling/src/main.rs | 31 +++++++++++++++-------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'examples/example-error-handling') diff --git a/examples/example-error-handling/src/main.rs b/examples/example-error-handling/src/main.rs index 05b451b..ec7e6c9 100644 --- a/examples/example-error-handling/src/main.rs +++ b/examples/example-error-handling/src/main.rs @@ -29,35 +29,41 @@ use std::io::Write; dispatcher!("hello", EntryHello); // Define error types -pack!(ErrorNoNameProvided = ()); -pack!(ErrorNameTooLong = u16); -pack!(ErrorNameNotAvailable = ()); +#[derive(Grouped)] +pub struct ErrorNoNameProvided; + +#[derive(Grouped, Wrap)] +pub struct ErrorNameTooLong(u16); + +#[derive(Grouped)] +pub struct ErrorNameNotAvailable; // Define success type -pack!(ResultName = String); +#[derive(Grouped, Wrap)] +pub struct ResultName(String); // Pre-registered names static VEC_REGISTERED_NAMES: &[&str] = &["Alice", "Bob", "Charlie", "David", "Eve"]; #[chain] fn handle_hello(args: EntryHello) -> Next { - let Some(name) = args.inner.first().cloned() else { + let Some(name) = args.0.first().cloned() else { // If no name is provided, pass ErrorNoNameProvided - return ErrorNoNameProvided::default().to_render(); + return ErrorNoNameProvided.to_render(); }; if name.len() > 10 { // If the name is too long, pass ErrorNameTooLong - return ErrorNameTooLong::new(name.len() as u16).to_render(); + return ErrorNameTooLong(name.len() as u16).to_render(); } if VEC_REGISTERED_NAMES.contains(&name.as_str()) { // If the name already exists, pass ErrorNameNotAvailable - return ErrorNameNotAvailable::default().to_render(); + return ErrorNameNotAvailable.to_render(); } // If the name is valid, pass ResultName - ResultName::new(name).to_render() + ResultName(name).to_render() } /// Renders a successful greeting with the given name. @@ -96,12 +102,7 @@ fn render_error_name_too_long(len: ErrorNameTooLong) -> RenderResult { #[renderer] fn render_entry_fallback(err: EntryFallback) -> RenderResult { let mut render_result = RenderResult::new(); - writeln!( - render_result, - "Command not found: \"{}\"", - err.inner.join(" ") - ) - .ok(); + writeln!(render_result, "Command not found: \"{}\"", err.0.join(" ")).ok(); render_result } -- cgit