diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-23 01:41:46 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-23 01:41:46 +0800 |
| commit | b75773a1177c6fe006bcd129b481ff42ecc3ec0e (patch) | |
| tree | c3cd26047dd0051c57ed38730981b3f1dd39bf3c /mingling | |
| parent | c9db14dcb7e03abe5e2c7a86f90205d0e76935cb (diff) | |
Add IO error example with type alias in group macro
Diffstat (limited to 'mingling')
| -rw-r--r-- | mingling/src/example_docs.rs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/mingling/src/example_docs.rs b/mingling/src/example_docs.rs index caa12ae..3171c22 100644 --- a/mingling/src/example_docs.rs +++ b/mingling/src/example_docs.rs @@ -1572,12 +1572,14 @@ pub mod example_lazy_resources {} /// ```bash /// cargo run --manifest-path examples/example-outside-type/Cargo.toml --quiet -- parse 42 /// cargo run --manifest-path examples/example-outside-type/Cargo.toml --quiet -- parse hello +/// cargo run --manifest-path examples/example-outside-type/Cargo.toml --quiet -- error /// ``` /// /// Output: /// ```plaintext /// Parsed number: 42 /// Parse error: invalid digit found in string +/// IO_ERROR: Error /// ``` /// /// Source code (./Cargo.toml) @@ -1599,9 +1601,15 @@ pub mod example_lazy_resources {} /// Source code (./src/main.rs) /// ```ignore /// use mingling::{macros::group, prelude::*}; -/// use std::num::ParseIntError; +/// use std::{io::ErrorKind::Other, num::ParseIntError}; /// /// dispatcher!("parse"); +/// dispatcher!("error"); +/// +/// #[chain] +/// fn handle_entry_error(_args: EntryError) -> Next { +/// std::io::Error::new(Other, "Error").to_render() +/// } /// /// // --------- IMPORTANT --------- /// // You can directly use the `group!` macro to define outside types as types @@ -1610,6 +1618,10 @@ pub mod example_lazy_resources {} /// // / /// // vvvvvvvvvvvvv /// group!(ParseIntError); +/// group!(ErrorIo = std::io::Error); +/// // ^^^^^^^^^^^^^^^^^^^^^^^^ +/// // \_____________ For types whose names may cause ambiguity, +/// // you can use this syntax to create an alias simultaneously /// // --------- IMPORTANT --------- /// /// pack!(ParsedNumber = i32); @@ -1644,9 +1656,18 @@ pub mod example_lazy_resources {} /// r_println!("Parse error: {}", err); /// } /// +/// /// Renderer for IO errors — using `std::io::Error` registered as `ErrorIo`. +/// // ________ Must use alias `ErrorIo` here, not bare `std::io::Error` +/// // / +/// #[renderer] // vvvvvvv +/// fn render_error_io(err: ErrorIo) { +/// r_println!("IO_ERROR: {}", err.to_string()); +/// } +/// /// fn main() { /// let mut program = ThisProgram::new(); /// program.with_dispatcher(CMDParse); +/// program.with_dispatcher(CMDError); /// program.exec_and_exit(); /// } /// |
