From 2aa7bda3cb21ce6c052b82e08bcab79a625d04f2 Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Sun, 31 May 2026 02:42:52 +0800 Subject: Enhance code quality across the entire codebase --- examples/example-custom-pickable/src/main.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'examples/example-custom-pickable/src/main.rs') diff --git a/examples/example-custom-pickable/src/main.rs b/examples/example-custom-pickable/src/main.rs index 466ae43..a2aa662 100644 --- a/examples/example-custom-pickable/src/main.rs +++ b/examples/example-custom-pickable/src/main.rs @@ -14,7 +14,7 @@ //! Failed to parse address //! ``` -use mingling::{Groupped, macros::route, parser::Pickable, prelude::*}; +use mingling::{macros::route, parser::Pickable, prelude::*, Groupped}; // Define types that can be recognized by Mingling // ________________________ `Pickable` trait needs to implement Default @@ -32,7 +32,7 @@ impl Pickable for Address { type Output = Address; fn pick(args: &mut mingling::parser::Argument, flag: mingling::Flag) -> Option { // Extract the raw string from Argument using the Flag - let raw: String = args.pick_argument(flag)?.to_string(); + let raw: String = args.pick_argument(flag)?.clone(); // Use TryFrom to parse the address Address::try_from(raw).ok() @@ -50,11 +50,13 @@ fn handle_connect(prev: EntryConnect) -> Next { connect.to_chain() } +/// Renders the connected address. #[renderer] fn render_address(addr: Address) { r_println!("Connected to \"{}\"", addr.to_string()); } +/// Renders the error message when address parsing fails. #[renderer] fn render_error_parse_address_failed(_: ErrorParseAddressFailed) { r_println!("Failed to parse address"); @@ -93,13 +95,13 @@ impl TryFrom for Address { for (i, part) in ip_parts.iter().enumerate() { ip[i] = part .parse::() - .map_err(|_| format!("Invalid IP octet: {}", part))?; + .map_err(|_| format!("Invalid IP octet: {part}"))?; } // Parse port let port = port_str .parse::() - .map_err(|_| format!("Invalid port: {}", port_str))?; + .map_err(|_| format!("Invalid port: {port_str}"))?; Ok(Address { ip, port }) } -- cgit