From 7585e16f9d4b682a0f77521653ee765b782a6e4c Mon Sep 17 00:00:00 2001 From: Philipp Schuster Date: Wed, 21 May 2025 13:08:04 +0200 Subject: [PATCH] misc: option_parser: streamline #[source] and Error impl This streamlines the Error implementation in the Cloud Hypervisor code base to match the remaining parts so that everything follows the agreed conventions. These are leftovers missed in the previous commits. Signed-off-by: Philipp Schuster On-behalf-of: SAP philipp.schuster@sap.com --- option_parser/src/lib.rs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/option_parser/src/lib.rs b/option_parser/src/lib.rs index 2d4cce017..61d1c44de 100644 --- a/option_parser/src/lib.rs +++ b/option_parser/src/lib.rs @@ -155,7 +155,9 @@ impl OptionParser { pub struct Toggle(pub bool); +#[derive(Error, Debug)] pub enum ToggleParseError { + #[error("invalid value: {0}")] InvalidValue(String), } @@ -176,8 +178,9 @@ impl FromStr for Toggle { pub struct ByteSized(pub u64); -#[derive(Debug)] +#[derive(Error, Debug)] pub enum ByteSizedParseError { + #[error("invalid value: {0}")] InvalidValue(String), } @@ -207,7 +210,9 @@ impl FromStr for ByteSized { pub struct IntegerList(pub Vec); +#[derive(Error, Debug)] pub enum IntegerListParseError { + #[error("invalid value: {0}")] InvalidValue(String), } @@ -297,11 +302,16 @@ impl TupleValue for Vec { pub struct Tuple(pub Vec<(S, T)>); +#[derive(Error, Debug)] pub enum TupleError { + #[error("invalid value: {0}")] InvalidValue(String), - SplitOutsideBrackets(OptionParserError), - InvalidIntegerList(IntegerListParseError), - InvalidInteger(ParseIntError), + #[error("split outside brackets: {0}")] + SplitOutsideBrackets(#[source] OptionParserError), + #[error("invalid integer list: {0}")] + InvalidIntegerList(#[source] IntegerListParseError), + #[error("invalid integer: {0}")] + InvalidInteger(#[source] ParseIntError), } impl FromStr for Tuple { @@ -339,7 +349,9 @@ impl FromStr for Tuple { #[derive(Default)] pub struct StringList(pub Vec); +#[derive(Error, Debug)] pub enum StringListParseError { + #[error("invalid value: {0}")] InvalidValue(String), }