Skip to main content

Error

Struct Error 

Source
pub struct Error { /* private fields */ }
Expand description

A parse failure.

Implementations§

Source§

impl Error

Source

pub fn unknown_flag(offset: usize, token: impl Into<String>) -> Self

A flag-like word, at offset, that matched nothing.

Source

pub fn unexpected_arg(offset: usize, token: impl Into<String>) -> Self

A word, at offset, that nothing could hold.

Source

pub fn missing_value(offset: usize, flag: impl Into<String>) -> Self

flag, at offset, needed a value and did not get one.

Source

pub fn unexpected_value( offset: usize, flag: impl Into<String>, value: &[u8], ) -> Self

flag, at offset, takes no value but was given value.

Source

pub fn missing_required(offset: usize, flag: impl Into<String>) -> Self

The required flag never appeared. The offset is the end of the line.

Source

pub fn missing_argument(offset: usize, name: impl Into<String>) -> Self

The required positional name was never filled. The offset is the end of the line.

Source

pub fn required_by(offset: usize, target: impl Into<String>, name: &str) -> Self

name requires target, which has no value. The offset is the end of the line.

Source

pub fn conflict(offset: usize, name: impl Into<String>, other: &str) -> Self

name and other exclude each other and were both given.

Source

pub fn missing_one_of( offset: usize, group: impl Into<String>, members: &[&str], ) -> Self

The required group group had none of members.

Source

pub fn requires_double_dash(offset: usize, name: impl Into<String>) -> Self

The word at offset reached name, which only takes words after --.

Source

pub fn help(command: &'static Command, long: bool) -> Self

-h (long == false) or --help for command.

Source

pub fn bare_help(command: &'static Command) -> Self

A bare invocation of an arg_required_else_help command.

Source

pub fn version(command: &'static Command) -> Self

-V/--version.

Source

pub fn within(self, name: &'static str) -> Self

Record that this came from within subcommand name, for the usage line and for what Error::suggested looks among.

Source

pub fn suggested(self, root: &'static Command) -> Self

Look among what root and the subcommand it failed in take for what an unknown flag or word was probably meant to be: Error::similar then has it. Args::parse_words and what is built on it do this; a parse through Args::parse_argv does not.

Source

pub fn similar(&self) -> Option<&str>

What the flag, subcommand or value at fault was probably meant to be, when something close to it is accepted there.

Source

pub fn render_help(&self, program: &str) -> Option<String>

The help to show for a ErrorKind::HelpRequested, program leading the usage line; plain, see Error::render_help_styled for color.

Source

pub fn version_text(&self, program: &str) -> Option<String>

program version for a ErrorKind::VersionRequested.

Source

pub fn is_bare_help(&self) -> bool

Help for a bare invocation, which is an error to report rather than an answer.

Source

pub fn missing_subcommand(offset: usize) -> Self

A required subcommand was not given. The offset is the end of the line.

Source

pub fn invalid_value( offset: usize, flag: impl Into<String>, value: &[u8], cause: impl Into<BoxError>, ) -> Self

value given to flag at offset was rejected by its type.

Source

pub fn kind(&self) -> ErrorKind

The class of failure.

Source

pub fn offset(&self) -> usize

Byte offset into the flattened command line.

Source

pub fn token(&self) -> Option<&str>

The flag or word the failure is about, if there is one.

Source

pub fn value(&self) -> Option<&str>

Source

pub fn is_cut(&self) -> bool

Whether backtracking past this error is forbidden.

Source§

impl Error

Source

pub fn message(&self, style: Style) -> String

What went wrong, as Display says it, with what was typed painted in the palette’s invalid and what is missing in valid.

Source

pub fn tip(&self, style: Style) -> Option<String>

tip: a similar flag exists: … for an error that has Error::similar, painted as what is missing is.

Source

pub fn render(&self, style: Style) -> String

The whole report for an error that is not help or version: error: …, a tip when something close was accepted, and a pointer to --help.

Source

pub fn render_help_styled(&self, program: &str, style: Style) -> Option<String>

Error::render_help, painted with style.

Trait Implementations§

Source§

impl Debug for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for Error

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for Error

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl<'i, E> FromExternalError<Argv<'i>, E> for Error
where E: Error + Send + Sync + 'static,

Lets try_map report a conversion failure. It backtracks, like any winnow error; the flag parsers in crate::combinator convert values themselves and commit, so their errors can name the flag.

Source§

fn from_external_error(input: &Argv<'i>, e: E) -> Self

Like ParserError::from_input but also include an external error.
Source§

impl ModalError for Error

Source§

fn cut(self) -> Self

Prevent backtracking, bubbling the error up to the top
Source§

fn backtrack(self) -> Self

Enable backtracking support
Source§

impl<'i, const N: usize> Parser<Argv<'i>, Arg<'i>, Error> for Named<N>

One occurrence of the flag’s name, value not yet read.

Source§

fn parse_next(&mut self, input: &mut Argv<'i>) -> Result<Arg<'i>, Error>

Take tokens from the Stream, turning it into the output Read more
Source§

fn parse( &mut self, input: I, ) -> Result<O, ParseError<I, <E as ParserError<I>>::Inner>>
where Self: Sized, I: Stream + StreamIsPartial, E: ParserError<I>, <E as ParserError<I>>::Inner: ParserError<I>,

Parse all of input, generating O from it Read more
Source§

fn parse_iter(&mut self, input: I) -> ParseIter<'_, Self, I, O, E> ⓘ
where Self: Sized, I: Stream + StreamIsPartial, E: ParserError<I>, <E as ParserError<I>>::Inner: ParserError<I>,

Repeat this parse until all of input is consumed, generating O from it Read more
Source§

fn parse_peek(&mut self, input: I) -> Result<(I, O), E>

Take tokens from the Stream, turning it into the output Read more
Source§

fn by_ref(&mut self) -> ByRef<'_, Self, I, O, E>
where Self: Sized,

Treat &mut Self as a parser Read more
Source§

fn value<O2>(self, val: O2) -> Value<Self, I, O, O2, E>
where Self: Sized, O2: Clone,

Produce the provided value Read more
Source§

fn default_value<O2>(self) -> DefaultValue<Self, I, O, O2, E>
where Self: Sized, O2: Default,

Produce a type’s default value Read more
Source§

fn void(self) -> Void<Self, I, O, E>
where Self: Sized,

Discards the output of the Parser Read more
Source§

fn output_into<O2>(self) -> OutputInto<Self, I, O, O2, E>
where Self: Sized, O: Into<O2>,

Convert the parser’s output to another type using std::convert::From Read more
Source§

fn take(self) -> Take<Self, I, O, E>
where Self: Sized, I: Stream,

Produce the consumed input as produced value. Read more
Source§

fn with_taken(self) -> WithTaken<Self, I, O, E>
where Self: Sized, I: Stream,

Produce the consumed input with the output Read more
Source§

fn span(self) -> Span<Self, I, O, E>
where Self: Sized, I: Stream + Location,

Produce the location of the consumed input as produced value. Read more
Source§

fn with_span(self) -> WithSpan<Self, I, O, E>
where Self: Sized, I: Stream + Location,

Produce the location of consumed input with the output Read more
Source§

fn map<G, O2>(self, map: G) -> Map<Self, G, I, O, O2, E>
where G: FnMut(O) -> O2, Self: Sized,

Maps a function over the output of a parser Read more
Source§

fn try_map<G, O2, E2>(self, map: G) -> TryMap<Self, G, I, O, O2, E, E2>
where Self: Sized, G: FnMut(O) -> Result<O2, E2>, I: Stream, E: FromExternalError<I, E2> + ParserError<I>,

Applies a function returning a Result over the output of a parser. Read more
Source§

fn verify_map<G, O2>(self, map: G) -> VerifyMap<Self, G, I, O, O2, E>
where Self: Sized, G: FnMut(O) -> Option<O2>, I: Stream, E: ParserError<I>,

Source§

fn flat_map<G, H, O2>(self, map: G) -> FlatMap<Self, G, H, I, O, O2, E>
where Self: Sized, G: FnMut(O) -> H, H: Parser<I, O2, E>,

Creates a parser from the output of this one Read more
Source§

fn parse_to<O2>(self) -> ParseTo<Self, I, O, O2, E>
where Self: Sized, I: Stream, O: ParseSlice<O2>, E: ParserError<I>,

Apply std::str::FromStr to the output of the parser Read more
Source§

fn verify<G, O2>(self, filter: G) -> Verify<Self, G, I, O, O2, E>
where Self: Sized, G: FnMut(&O2) -> bool, I: Stream, O: Borrow<O2>, E: ParserError<I>, O2: ?Sized,

Returns the output of the child parser if it satisfies a verification function. Read more
Source§

fn context<C>(self, context: C) -> Context<Self, I, O, E, C>
where Self: Sized, I: Stream, E: AddContext<I, C> + ParserError<I>, C: Clone + Debug,

If parsing fails, add context to the error Read more
Source§

fn context_with<F, C, FI>( self, context: F, ) -> ContextWith<Self, I, O, E, F, C, FI>
where Self: Sized, I: Stream, E: AddContext<I, C> + ParserError<I>, F: Fn() -> FI + Clone, C: Debug, FI: Iterator<Item = C>,

If parsing fails, dynamically add context to the error Read more
Source§

fn map_err<G, E2>(self, map: G) -> MapErr<Self, G, I, O, E, E2>
where G: FnMut(E) -> E2, Self: Sized,

Maps a function over the error of a parser Read more
Source§

fn complete_err(self) -> CompleteErr<Self, I, O, E>
where Self: Sized,

Source§

fn err_into<E2>(self) -> ErrInto<Self, I, O, E, E2>
where Self: Sized, E: Into<E2>,

Convert the parser’s error to another type using std::convert::From
Source§

impl<'i> ParserError<Argv<'i>> for Error

Source§

fn or(self, other: Self) -> Self

Keep whichever of the two says more: a specific failure beats a bare “did not match”, and otherwise the later branch wins, as in winnow.

Source§

type Inner = Error

Generally, Self Read more
Source§

fn from_input(input: &Argv<'i>) -> Self

Creates an error from the input position
Source§

fn is_backtrack(&self) -> bool

Is backtracking and trying new parse branches allowed?
Source§

fn into_inner(self) -> Result<Self::Inner, Self>

Unwrap the mode, returning the underlying error, if present
Source§

fn assert(input: &I, _message: &'static str) -> Self
where I: Debug,

Process a parser assertion
Source§

fn incomplete(input: &I, _needed: Needed) -> Self

There was not enough data to determine the appropriate action Read more
Source§

fn append(self, _input: &I, _token_start: &<I as Stream>::Checkpoint) -> Self

Like ParserError::from_input but merges it with the existing error. Read more
Source§

fn is_incomplete(&self) -> bool

Is more data Needed Read more
Source§

fn needed(&self) -> Option<Needed>

Extract the Needed data, if present Read more
Source§

impl PartialEq for Error

Source§

fn eq(&self, other: &Self) -> bool

Equal when they report the same thing at the same place; causes are not compared.

1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Error

§

impl !UnwindSafe for Error

§

impl Freeze for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.