diff --git a/src/flags.rs b/src/flags.rs index 98198f0..0fd77d6 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -223,7 +223,7 @@ impl ArgState /// # Note /// This mutates the argument state container indefinately, and multiple calls to it will keep the mutated state. /// So this might not behave as expected (e.g. callbacks marked `single` that were fired in the first call will not be fired in the second, etc.) - pub fn parse>(&mut self, input: I) -> Result>, CtxError> + pub fn parse>(&mut self, input: I) -> Result>, ContextualError> where I: Iterator { let mut output = Vec::with_capacity(self.flags.len()); @@ -273,19 +273,24 @@ pub struct Error /// An argument parsing error with context #[repr(transparent)] #[derive(Debug)] -pub struct CtxError(Error); +pub struct ContextualError(Error); #[derive(Debug, Clone, Copy)] pub struct ErrorContext<'a> { + /// The error-throwing flag pub flag: &'a Kind<'static>, + /// The argument string pub arg: &'a String, + /// The index of the argument string pub arg_idx: &'a usize, + /// Message from the failing flag callback, if any pub desc: Option<&'a String>, + /// The error report pub from: &'a eyre::Report, } -impl CtxError +impl ContextualError { /// The inner error #[inline] pub fn inner(&self) -> &Error @@ -343,7 +348,7 @@ impl fmt::Display for Error } } -impl fmt::Display for CtxError +impl fmt::Display for ContextualError { #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -371,9 +376,9 @@ impl Error } /// Add context to this error - pub fn with_context(self) -> CtxError + pub fn with_context(self) -> ContextualError { - CtxError(Self { + ContextualError(Self { flag: self.flag.clone(), arg: self.arg.clone(), desc: self.desc.clone(), @@ -382,17 +387,17 @@ impl Error } } -impl From for CtxError +impl From for ContextualError { - fn from(from: Error) -> Self + #[inline] fn from(from: Error) -> Self { from.with_context() } } -impl From for eyre::Report +impl From for eyre::Report { - fn from(from: CtxError) -> Self + #[inline] fn from(from: ContextualError) -> Self { from.0.from }