From 9c3d22ad86b7c3e915f734b2c6c137c6b8b7474e Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Wed, 15 Jul 2026 16:18:07 +0800 Subject: refactor: remove ParseError variant from PickerArgResult The ParseError variant has been removed and its usages in From, is_found, is_err, and unwrap have been updated to use NotFound instead, simplifying the error handling model. --- mingling_picker/src/infos.rs | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/mingling_picker/src/infos.rs b/mingling_picker/src/infos.rs index 95a54da..f15ae88 100644 --- a/mingling_picker/src/infos.rs +++ b/mingling_picker/src/infos.rs @@ -2,11 +2,10 @@ use crate::{Pickable, PickerFlag}; /// Represents the result of parsing or looking up a value. /// -/// This enum is generic over the type being parsed. It models four possible outcomes: +/// This enum is generic over the type being parsed. It models three possible outcomes: /// - [`Unparsed`](PickerArgResult::Unparsed): The value has not yet been parsed (default). /// - [`Parsed`](PickerArgResult::Parsed): The value was successfully parsed into `Type`. /// - [`NotFound`](PickerArgResult::NotFound): The requested value could not be found. -/// - [`ParseError`](PickerArgResult::ParseError): The input could not be parsed due to a format error. #[derive(Default)] pub enum PickerArgResult { /// The value has not yet been parsed (default). @@ -18,20 +17,17 @@ pub enum PickerArgResult { /// The requested value could not be found. NotFound, - - /// The input could not be parsed due to a format error. - ParseError, } impl From> for PickerArgResult { /// Converts a `Result` into a `PickerArgResult`. /// /// - `Ok(value)` maps to [`Parsed(value)`](PickerArgResult::Parsed). - /// - `Err(_)` maps to [`ParseError`](PickerArgResult::ParseError). + /// - `Err(_)` maps to [`NotFound`](PickerArgResult::NotFound). fn from(result: Result) -> Self { match result { Ok(value) => PickerArgResult::Parsed(value), - Err(_) => PickerArgResult::ParseError, + Err(_) => PickerArgResult::NotFound, } } } @@ -68,7 +64,7 @@ impl PickerArgResult { } /// Returns `true` if the result is [`Parsed`](PickerArgResult::Parsed) or [`NotFound`](PickerArgResult::NotFound). - /// i.e., the value exists (was either found or not yet parsed, but not a parse error). + /// i.e., the value exists (was either found or not yet parsed). /// Typically indicates the value was "found" in some sense. /// /// # Examples @@ -81,29 +77,26 @@ impl PickerArgResult { /// /// let result: PickerArgResult = PickerArgResult::NotFound; /// assert!(result.is_found()); - /// - /// let result: PickerArgResult = PickerArgResult::ParseError; - /// assert!(!result.is_found()); /// ``` pub fn is_found(&self) -> bool { matches!(self, PickerArgResult::Parsed(_) | PickerArgResult::NotFound) } - /// Returns `true` if the result is [`ParseError`](PickerArgResult::ParseError). + /// Returns `true` if the result is [`Unparsed`](PickerArgResult::Unparsed) or [`NotFound`](PickerArgResult::NotFound). /// /// # Examples /// /// ``` /// use mingling_picker::PickerArgResult; /// - /// let result: PickerArgResult = PickerArgResult::ParseError; + /// let result: PickerArgResult = PickerArgResult::Unparsed; /// assert!(result.is_err()); /// /// let result: PickerArgResult = PickerArgResult::Parsed(10); /// assert!(!result.is_err()); /// ``` pub fn is_err(&self) -> bool { - matches!(self, PickerArgResult::ParseError) + !matches!(self, PickerArgResult::Parsed(_)) } /// Returns `Some(&Type)` if [`Parsed`](PickerArgResult::Parsed), otherwise `None`. @@ -176,9 +169,6 @@ impl PickerArgResult { PickerArgResult::NotFound => { panic!("called `PickerArgResult::unwrap()` on a `NotFound` value") } - PickerArgResult::ParseError => { - panic!("called `PickerArgResult::unwrap()` on a `ParseError` value") - } } } -- cgit