aboutsummaryrefslogtreecommitdiff
path: root/examples/example-pack-err
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 /examples/example-pack-err
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 'examples/example-pack-err')
-rw-r--r--examples/example-pack-err/Cargo.lock235
-rw-r--r--examples/example-pack-err/Cargo.toml16
-rw-r--r--examples/example-pack-err/page.toml10
-rw-r--r--examples/example-pack-err/src/main.rs151
-rw-r--r--examples/example-pack-err/test.toml35
5 files changed, 0 insertions, 447 deletions
diff --git a/examples/example-pack-err/Cargo.lock b/examples/example-pack-err/Cargo.lock
deleted file mode 100644
index bcfbb41..0000000
--- a/examples/example-pack-err/Cargo.lock
+++ /dev/null
@@ -1,235 +0,0 @@
-# This file is automatically @generated by Cargo.
-# It is not intended for manual editing.
-version = 4
-
-[[package]]
-name = "equivalent"
-version = "1.0.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
-
-[[package]]
-name = "example-pack-err"
-version = "0.1.0"
-dependencies = [
- "mingling",
- "serde",
-]
-
-[[package]]
-name = "hashbrown"
-version = "0.17.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
-
-[[package]]
-name = "indexmap"
-version = "2.14.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"
-dependencies = [
- "equivalent",
- "hashbrown",
-]
-
-[[package]]
-name = "itoa"
-version = "1.0.18"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"
-
-[[package]]
-name = "just_fmt"
-version = "0.2.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6170dccbc3ea15dfb7f2da964097f814aba1dd8f746d4ffc56f33245c38e6d96"
-
-[[package]]
-name = "memchr"
-version = "2.8.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "88904434abc2901f197fe8cc55f0445e7ded921dba5911dad2e2b39b48e663c4"
-
-[[package]]
-name = "might_be_async"
-version = "0.1.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "eca871cea620b07bd2e6da0c883891a25bead698c43a9ab64b0fd663a7a78d5f"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
- "toml",
-]
-
-[[package]]
-name = "mingling"
-version = "0.5.0"
-dependencies = [
- "mingling_core",
- "mingling_macros",
- "serde",
-]
-
-[[package]]
-name = "mingling_core"
-version = "0.5.0"
-dependencies = [
- "just_fmt",
- "might_be_async",
- "serde",
- "serde_json",
-]
-
-[[package]]
-name = "mingling_macros"
-version = "0.5.0"
-dependencies = [
- "just_fmt",
- "proc-macro2",
- "quote",
- "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 = "serde"
-version = "1.0.228"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
-dependencies = [
- "serde_core",
- "serde_derive",
-]
-
-[[package]]
-name = "serde_core"
-version = "1.0.228"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
-dependencies = [
- "serde_derive",
-]
-
-[[package]]
-name = "serde_derive"
-version = "1.0.228"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
-name = "serde_json"
-version = "1.0.150"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9"
-dependencies = [
- "itoa",
- "memchr",
- "serde",
- "serde_core",
- "zmij",
-]
-
-[[package]]
-name = "serde_spanned"
-version = "0.6.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3"
-dependencies = [
- "serde",
-]
-
-[[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 = "toml"
-version = "0.8.23"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dc1beb996b9d83529a9e75c17a1686767d148d70663143c7854d8b4a09ced362"
-dependencies = [
- "serde",
- "serde_spanned",
- "toml_datetime",
- "toml_edit",
-]
-
-[[package]]
-name = "toml_datetime"
-version = "0.6.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c"
-dependencies = [
- "serde",
-]
-
-[[package]]
-name = "toml_edit"
-version = "0.22.27"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"
-dependencies = [
- "indexmap",
- "serde",
- "serde_spanned",
- "toml_datetime",
- "toml_write",
- "winnow",
-]
-
-[[package]]
-name = "toml_write"
-version = "0.1.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5d99f8c9a7727884afe522e9bd5edbfc91a3312b36a77b5fb8926e4c31a41801"
-
-[[package]]
-name = "unicode-ident"
-version = "1.0.24"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
-
-[[package]]
-name = "winnow"
-version = "0.7.15"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"
-dependencies = [
- "memchr",
-]
-
-[[package]]
-name = "zmij"
-version = "1.0.21"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"
diff --git a/examples/example-pack-err/Cargo.toml b/examples/example-pack-err/Cargo.toml
deleted file mode 100644
index ddab6fd..0000000
--- a/examples/example-pack-err/Cargo.toml
+++ /dev/null
@@ -1,16 +0,0 @@
-[package]
-name = "example-pack-err"
-version = "0.1.0"
-edition = "2024"
-
-[dependencies]
-serde = { version = "1.0.228", features = ["derive"] }
-
-[dependencies.mingling]
-path = "../../mingling"
-features = [
- "structural_renderer",
- "extras",
-]
-
-[workspace]
diff --git a/examples/example-pack-err/page.toml b/examples/example-pack-err/page.toml
deleted file mode 100644
index 7423087..0000000
--- a/examples/example-pack-err/page.toml
+++ /dev/null
@@ -1,10 +0,0 @@
-[example]
-id = "example-pack-err"
-name = "Pack an Error"
-icon = "🛑"
-category = "macros"
-desc = """
-Demonstrates how to use the `pack_err!` macro to define error types with automatic `name` field (snake_case at compile time) and optional `info` field. Also shows `--json` serialization when `structural_renderer` is enabled.
-"""
-tags = ["pack_err!", "extras", "structural_renderer", "--json"]
-files = ["src/main.rs", "Cargo.toml"]
diff --git a/examples/example-pack-err/src/main.rs b/examples/example-pack-err/src/main.rs
deleted file mode 100644
index e30e4cb..0000000
--- a/examples/example-pack-err/src/main.rs
+++ /dev/null
@@ -1,151 +0,0 @@
-//! Example `pack_err!`
-//!
-//! > This example demonstrates how to use the `pack_err!` macro to define error types
-//! > with automatic `name` field (set to snake_case at compile time) and optional `info` field.
-//! > Also demonstrates `--json` serialization when `structural_renderer` is enabled.
-//!
-//! Run:
-//! ```bash
-//! cargo run --manifest-path examples/example-pack-err/Cargo.toml --quiet -- find
-//! cargo run --manifest-path examples/example-pack-err/Cargo.toml --quiet -- find Cargo.toml
-//! cargo run --manifest-path examples/example-pack-err/Cargo.toml --quiet -- find src
-//! cargo run --manifest-path examples/example-pack-err/Cargo.toml --quiet -- find-structural --json
-//! cargo run --manifest-path examples/example-pack-err/Cargo.toml --quiet -- find-structural Cargo.toml --json
-//! cargo run --manifest-path examples/example-pack-err/Cargo.toml --quiet -- find-structural src --json
-//! ```
-//!
-//! Output:
-//! ```plaintext
-//! Search path not provided
-//! Not a directory: Cargo.toml
-//! Found directory: src
-//! {"name":"error_not_found"}
-//! {"name":"error_not_dir","info":"Cargo.toml"}
-//! {"inner":"src"}
-//! {"name":"error_not_found_structural"}
-//! {"name":"error_not_dir_structural","info":"Cargo.toml"}
-//! ```
-
-use mingling::prelude::*;
-use mingling::setup::StructuralRendererSetup;
-use std::io::Write;
-use std::path::PathBuf;
-
-dispatcher!("find", EntryFind);
-dispatcher!("find-structural", EntryFindStructural);
-
-// --------- IMPORTANT ---------
-// `pack_err!` is a convenient macro for defining error types.
-//
-// Simple form: pack_err!(ErrorNotFound);
-// Typed form: pack_err!(ErrorNotDir = PathBuf);
-//
-// The simple form generates a struct with `name: String` and `impl Default`.
-// name = "error_not_found" (automatically snake_cased at compile time)
-//
-// The typed form additionally generates `pub fn new(info)`.
-// name = "error_not_dir"
-//
-// When `structural_renderer` is enabled, the struct also gets
-// `#[derive(serde::Serialize)]` for --json / --yaml output.
-// --------- IMPORTANT ---------
-
-// Simple form — name = "error_not_found"
-pack_err!(ErrorNotFound);
-
-// Typed form — name = "error_not_dir"
-pack_err!(ErrorNotDir = PathBuf);
-
-// Simple form — with StructuralData support for --json / --yaml
-pack_err_structural!(ErrorNotFoundStructural);
-
-// Typed form — with StructuralData support for --json / --yaml
-pack_err_structural!(ErrorNotDirStructural = PathBuf);
-
-// Success type with StructuralData support
-pack_structural!(ResultPath = PathBuf);
-
-#[chain]
-fn handle_find(args: EntryFind) -> Next {
- let Some(path_str) = args.inner.first().cloned() else {
- // No path provided → use the simple error form (Default)
- return ErrorNotFound::default().to_render();
- };
-
- let path = PathBuf::from(&path_str);
- if path.is_dir() {
- // Is a directory → success
- ResultPath::new(path).to_render()
- } else {
- // Not a directory (or doesn't exist) → use the typed error form
- ErrorNotDir::new(path).to_render()
- }
-}
-
-#[chain]
-fn handle_find_structural(args: EntryFindStructural) -> Next {
- let Some(path_str) = args.inner.first().cloned() else {
- // No path provided → use the simple error form (Default)
- return ErrorNotFoundStructural::default().to_render();
- };
-
- let path = PathBuf::from(&path_str);
- if path.is_dir() {
- // Is a directory → success
- ResultPath::new(path).to_render()
- } else {
- // Not a directory (or doesn't exist) → use the typed error form
- ErrorNotDirStructural::new(path).to_render()
- }
-}
-
-/// Renders the successful result with the found directory path.
-#[renderer]
-fn render_result_path(path: ResultPath) -> RenderResult {
- let mut render_result = RenderResult::new();
- writeln!(render_result, "Found directory: {}", path.display()).ok();
- render_result
-}
-
-/// Renders the error when no search path is provided.
-#[renderer]
-fn render_error_not_found(_: ErrorNotFound) -> RenderResult {
- let mut render_result = RenderResult::new();
- writeln!(render_result, "Search path not provided").ok();
- render_result
-}
-
-/// Renders the error when the given path is not a directory.
-#[renderer]
-fn render_error_not_dir(err: ErrorNotDir) -> RenderResult {
- let mut render_result = RenderResult::new();
- writeln!(render_result, "Not a directory: {}", err.info.display()).ok();
- render_result
-}
-
-/// Renders the structural error when no search path is provided.
-#[renderer]
-fn render_error_not_found_structural(_: ErrorNotFoundStructural) -> RenderResult {
- let mut render_result = RenderResult::new();
- writeln!(render_result, "Search path not provided").ok();
- render_result
-}
-
-/// Renders the structural error when the given path is not a directory.
-#[renderer]
-fn render_error_not_dir_structural(err: ErrorNotDirStructural) -> RenderResult {
- let mut render_result = RenderResult::new();
- writeln!(render_result, "Not a directory: {}", err.info.display()).ok();
- render_result
-}
-
-gen_program!();
-
-fn main() {
- let mut program = ThisProgram::new();
-
- // Add StructuralRendererSetup to support --json / --yaml flags
- program.with_setup(StructuralRendererSetup);
-
- let _ = program.exec();
-}
diff --git a/examples/example-pack-err/test.toml b/examples/example-pack-err/test.toml
deleted file mode 100644
index c4509cb..0000000
--- a/examples/example-pack-err/test.toml
+++ /dev/null
@@ -1,35 +0,0 @@
-[[runs]]
-input = [ "find" ]
-
-expect.exit-code = 0
-expect.result = "Search path not provided"
-
-[[runs]]
-input = [ "find", "Cargo.toml" ]
-
-expect.exit-code = 0
-expect.result = "Not a directory: Cargo.toml"
-
-[[runs]]
-input = [ "find", "examples" ]
-
-expect.exit-code = 0
-expect.result = "Found directory: examples"
-
-[[runs]]
-input = [ "find-structural", "--json" ]
-
-expect.exit-code = 0
-expect.result = "{\"name\":\"error_not_found_structural\"}"
-
-[[runs]]
-input = [ "find-structural", "Cargo.toml", "--json" ]
-
-expect.exit-code = 0
-expect.result = "{\"name\":\"error_not_dir_structural\",\"info\":\"Cargo.toml\"}"
-
-[[runs]]
-input = [ "find-structural", "examples", "--json" ]
-
-expect.exit-code = 0
-expect.result = "{\"inner\":\"examples\"}"