flag error okay

master
Avril 4 years ago
parent dd8ed72b26
commit 1a8792b4d0
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -223,7 +223,7 @@ impl<U> ArgState<U>
/// # Note /// # Note
/// This mutates the argument state container indefinately, and multiple calls to it will keep the mutated state. /// 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.) /// 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<I,T: Into<String>>(&mut self, input: I) -> Result<Vec<Box<dyn Any+'static>>, CtxError> pub fn parse<I,T: Into<String>>(&mut self, input: I) -> Result<Vec<Box<dyn Any+'static>>, ContextualError>
where I: Iterator<Item=T> where I: Iterator<Item=T>
{ {
let mut output = Vec::with_capacity(self.flags.len()); let mut output = Vec::with_capacity(self.flags.len());
@ -273,19 +273,24 @@ pub struct Error
/// An argument parsing error with context /// An argument parsing error with context
#[repr(transparent)] #[repr(transparent)]
#[derive(Debug)] #[derive(Debug)]
pub struct CtxError(Error); pub struct ContextualError(Error);
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct ErrorContext<'a> pub struct ErrorContext<'a>
{ {
/// The error-throwing flag
pub flag: &'a Kind<'static>, pub flag: &'a Kind<'static>,
/// The argument string
pub arg: &'a String, pub arg: &'a String,
/// The index of the argument string
pub arg_idx: &'a usize, pub arg_idx: &'a usize,
/// Message from the failing flag callback, if any
pub desc: Option<&'a String>, pub desc: Option<&'a String>,
/// The error report
pub from: &'a eyre::Report, pub from: &'a eyre::Report,
} }
impl CtxError impl ContextualError
{ {
/// The inner error /// The inner error
#[inline] pub fn inner(&self) -> &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 #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result
{ {
@ -371,9 +376,9 @@ impl Error
} }
/// Add context to this 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(), flag: self.flag.clone(),
arg: self.arg.clone(), arg: self.arg.clone(),
desc: self.desc.clone(), desc: self.desc.clone(),
@ -382,17 +387,17 @@ impl Error
} }
} }
impl From<Error> for CtxError impl From<Error> for ContextualError
{ {
fn from(from: Error) -> Self #[inline] fn from(from: Error) -> Self
{ {
from.with_context() from.with_context()
} }
} }
impl From<CtxError> for eyre::Report impl From<ContextualError> for eyre::Report
{ {
fn from(from: CtxError) -> Self #[inline] fn from(from: ContextualError) -> Self
{ {
from.0.from from.0.from
} }

Loading…
Cancel
Save