Skip to main content

ParseResult

Struct ParseResult 

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

Outcome of parsing a raw argv slice against a CommandSchema.

Holds typed-but-unconverted values; callers pull values out via ParseResult::flag, ParseResult::get, etc. Conversion happens lazily at extraction time so a single result can be probed with different target types during tests without repeated parsing.

Implementations§

Source§

impl ParseResult

Source

pub fn flag(&self, name: &str) -> bool

Check whether a boolean flag was provided.

Source

pub fn get<T: FromArg>(&self, name: &str) -> Result<Option<T>>

Get the last value supplied for an option, converted via FromArg. Returns Ok(None) when the option is absent.

Looks up positional arguments as a fallback so callers don’t need two code paths for “option or argument by name”.

Source

pub fn require<T: FromArg>(&self, name: &str) -> Result<T>

Like ParseResult::get but errors if the value is missing.

The error variant depends on the name shape: dash-prefixed names (e.g. --num, -n) become MissingOption, everything else becomes MissingArgument. That way a command that marks an option as required via require::<T>("--num") gets a diagnostic mentioning the option, not a positional argument.

Source

pub fn all<T: FromArg>(&self, name: &str) -> Result<Vec<T>>

Get all values supplied for a repeatable option.

Source

pub fn subcommand(&self) -> Option<(&str, &ParseResult)>

Return the matched subcommand name and its parse result, if any.

Source

pub fn raw_value(&self, name: &str) -> Option<&str>

Raw access for advanced callers. Follows the same option/positional split as ParseResult::get: dash-prefixed names only look at option values; non-dash names look at options first, then positionals.

Trait Implementations§

Source§

impl Debug for ParseResult

Source§

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

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

impl Default for ParseResult

Source§

fn default() -> ParseResult

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.