Skip to main content

Error

Enum Error 

Source
#[non_exhaustive]
pub enum Error {
Show 19 variants DisplayHelp { help: String, }, DisplayVersion { version: String, }, DisplaySchema { schema: String, }, DisplayCompletion { completion: String, }, UnknownFlag { token: Vec<u8>, }, MissingValue { name: &'static str, possible_values: &'static [&'static str], }, UnexpectedValue { name: &'static str, }, UnexpectedArgument { token: Vec<u8>, usage: Option<String>, }, UnknownCommand { token: Vec<u8>, }, MissingSubcommand { name: &'static str, }, MissingRequired { name: &'static str, }, MissingRequiredArguments { argument: String, usage: String, }, DuplicateArgument { name: &'static str, usage: Option<String>, }, MissingRequirement { name: &'static str, required_by: &'static str, }, ConflictingArguments { name: &'static str, other: &'static str, }, InvalidOneOf { arguments: String, }, InvalidAnyOf { arguments: String, }, InvalidUtf8 { name: &'static str, value: Vec<u8>, }, InvalidValue { name: &'static str, value: String, reason: String, },
}
Expand description

A built-in parser action or command-line parsing failure.

Help, version, schema, and completion requests are represented alongside ordinary parsing errors so callers of the try_parse* methods can choose how to handle them.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

DisplayHelp

Generated help requested through the built-in help switch.

Fields

§help: String

Fully rendered help text for the selected command scope.

§

DisplayVersion

Version information requested through the built-in version action.

Fields

§version: String

Fully rendered version text for the selected command scope.

§

DisplaySchema

Machine-readable command schema requested through built-in discovery.

Fields

§schema: String

Pretty-printed JSON schema document for the selected command scope.

§

DisplayCompletion

Dynamic shell-completion output requested through Argx’s private completion protocol.

Fields

§completion: String

Completion candidates encoded for the generated shell adapter.

§

UnknownFlag

A flag-like token did not match any declared flag.

Fields

§token: Vec<u8>

Encoded token supplied by the caller.

§

MissingValue

A flag that consumes a value did not receive one.

Fields

§name: &'static str

Canonical user-facing argument label.

§possible_values: &'static [&'static str]

Finite values accepted by this option, when known.

§

UnexpectedValue

A value was attached to a switch that does not accept one.

Fields

§name: &'static str

Canonical user-facing argument label.

§

UnexpectedArgument

A word could not be assigned to any positional argument.

Fields

§token: Vec<u8>

Encoded token supplied by the caller.

§usage: Option<String>

Corrective usage for the selected command scope, when available.

§

UnknownCommand

A word did not match any child command when command selection was required.

Fields

§token: Vec<u8>

Encoded token supplied by the caller.

§

MissingSubcommand

A required subcommand field was not selected.

Fields

§name: &'static str

Canonical field name.

§

MissingRequired

A required field was not supplied during generated binding.

Fields

§name: &'static str

Canonical user-facing argument label.

§

MissingRequiredArguments

One or more required arguments were missing from a parsed command invocation.

Fields

§argument: String

Canonical CLI rendering of the missing argument.

§usage: String

Usage for the selected command scope.

§

DuplicateArgument

A scalar argument was supplied more than once.

Fields

§name: &'static str

Canonical user-facing argument label.

§usage: Option<String>

Corrective usage for the selected command scope, when available.

§

MissingRequirement

An argument required by another supplied argument was not available.

Fields

§name: &'static str

Canonical user-facing label of the missing argument.

§required_by: &'static str

Canonical user-facing label of the argument imposing the requirement.

§

ConflictingArguments

Two arguments declared to conflict were supplied together.

Fields

§name: &'static str

Canonical user-facing label of the argument declaring the conflict.

§other: &'static str

Canonical user-facing label of the conflicting argument.

§

InvalidOneOf

A one_of set had zero or multiple explicitly supplied members.

Fields

§arguments: String

Comma-separated canonical labels of the participating arguments.

§

InvalidAnyOf

An any_of set had no explicitly supplied member.

Fields

§arguments: String

Comma-separated canonical labels of the participating arguments.

§

InvalidUtf8

A text value was not valid UTF-8.

Fields

§name: &'static str

Canonical user-facing argument label.

§value: Vec<u8>

Encoded value supplied by the caller.

§

InvalidValue

A UTF-8 value could not be converted to the field’s Rust type.

Fields

§name: &'static str

Canonical user-facing argument label.

§value: String

Text supplied on argv.

§reason: String

Conversion failure reported by the target type.

Implementations§

Source§

impl Error

Source

pub const fn exit_code(&self) -> i32

Returns the process status used by Self::exit.

§Examples
let help = argx::Error::DisplayHelp { help: String::new() };
let failure = argx::Error::UnknownFlag { token: b"--bad".to_vec() };

assert_eq!(help.exit_code(), 0);
assert_eq!(failure.exit_code(), 2);
Source

pub fn exit(&self) -> !

Prints this result to the appropriate stream and terminates the process.

Help, version, schema, and completion requests are written to standard output and exit successfully. Parse and binding failures are written to standard error and exit with status 2.

Trait Implementations§

Source§

impl Clone for Error

Source§

fn clone(&self) -> Error

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
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, __formatter: &mut Formatter<'_>) -> Result

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

impl Eq for Error

Source§

impl Error for Error

1.30.0 · 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 From<Error> for Error

Source§

fn from(source: Error) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Error

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Error

Auto Trait Implementations§

§

impl Freeze for Error

§

impl RefUnwindSafe for Error

§

impl Send for Error

§

impl Sync for Error

§

impl Unpin for Error

§

impl UnsafeUnpin for Error

§

impl UnwindSafe 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.

Layout§

Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...) attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.

Size: 64 bytes

Size for each variant:

  • DisplayHelp: 32 bytes
  • DisplayVersion: 32 bytes
  • DisplaySchema: 32 bytes
  • DisplayCompletion: 32 bytes
  • UnknownFlag: 32 bytes
  • MissingValue: 40 bytes
  • UnexpectedValue: 24 bytes
  • UnexpectedArgument: 56 bytes
  • UnknownCommand: 32 bytes
  • MissingSubcommand: 24 bytes
  • MissingRequired: 24 bytes
  • MissingRequiredArguments: 56 bytes
  • DuplicateArgument: 48 bytes
  • MissingRequirement: 40 bytes
  • ConflictingArguments: 40 bytes
  • InvalidOneOf: 32 bytes
  • InvalidAnyOf: 32 bytes
  • InvalidUtf8: 48 bytes
  • InvalidValue: 64 bytes