[−][src]Enum argwerk::ErrorKind
The kind of an error.
Variants
Encountered an argument that was not supported.
An unsupported argument is triggered when none of the branches in the parser matches the current agument.
Examples
argwerk::define! { struct Args { } // This errors because `bar` is not a supported switch, nor do we // match any positional arguments. ["--file", arg] => {} } let error = Args::parse(vec!["bar"]).unwrap_err(); assert!(matches!(error.kind(), argwerk::ErrorKind::UnsupportedArgument { .. }));
Encountered a switch that was not supported.
An unsupported switch is caused by the same reason as an unsupported
argument, but it's prefixed with a hyphen -
.
Examples
argwerk::define! { #[usage = "command [-h]"] struct Args { } // This errors because `--path` is not a supported switch. But // `"--file"` is. ["--file", arg] => {} } let error = Args::parse(vec!["--path"]).unwrap_err(); assert!(matches!(error.kind(), argwerk::ErrorKind::UnsupportedSwitch { .. }));
When a parameter to an argument is missing.
Examples
argwerk::define! { struct Args { } // This errors because `--file` requires an argument `path`, but // that is not provided. ["--file", path] => {} } let error = Args::parse(vec!["--file"]).unwrap_err(); assert!(matches!(error.kind(), argwerk::ErrorKind::MissingSwitchArgument { .. }));
Fields of MissingSwitchArgument
When a positional argument is missing.
Examples
argwerk::define! { struct Args { } // This errors because `b` is a required argument, but we only have // one which matches `a`. [a, b] => {} } let error = Args::parse(vec!["foo"]).unwrap_err(); assert!(matches!(error.kind(), argwerk::ErrorKind::MissingPositional { .. }));
Fields of MissingPositional
name: &'static str
The name of the argument missing like path
in <path>
.
When a positional argument is missing.
Examples
argwerk::define! { struct Args { #[required = "--name must be used"] name: String, } ["--name", n] => { name = Some(n); } [rest] => {} } let error = Args::parse(vec!["foo"]).unwrap_err(); assert!(matches!(error.kind(), argwerk::ErrorKind::MissingRequired { name: "name", .. }));
Fields of MissingRequired
When an error has been raised while processing an argument, typically when something is being parsed.
Examples
argwerk::define! { #[usage = "command [-h]"] struct Args { } // This errors because we raise an error in the branch body. ["foo"] => { Err("something went wrong") } } let error = Args::parse(vec!["foo"]).unwrap_err(); assert!(matches!(error.kind(), argwerk::ErrorKind::Error { .. }));
Fields of Error
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for ErrorKind
[src]
impl Send for ErrorKind
[src]
impl Sync for ErrorKind
[src]
impl Unpin for ErrorKind
[src]
impl !UnwindSafe for ErrorKind
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,