ParsedArgs

Struct ParsedArgs 

Source
pub struct ParsedArgs {
    pub flags: HashSet<String>,
    pub options: HashMap<String, String>,
    pub positional: Vec<String>,
}
Expand description

Represents a set of parsed arguments.

You get this struct back after a successful call to Parser::parse().

Fields§

§flags: HashSet<String>

A set of all flags that were present.

§options: HashMap<String, String>

A map of all options and their string values.

§positional: Vec<String>

A vector of all positional arguments in the order they appeared.

Implementations§

Source§

impl ParsedArgs

Source

pub fn get_value_as<T: FromStr>(&self, name: &str) -> Option<Result<T, T::Err>>

Gets and parses the value of an option into a specific type.

This method attempts to find an option by its name and then parse its string value into any type T that implements FromStr.

§Returns
  • None: If the option was not provided by the user.
  • Some(Ok(value)): If the option was found and successfully parsed.
  • Some(Err(error)): If the option was found but parsing failed.
§Examples
// Assuming `results` is a ParsedArgs
// let port = results.get_value_as::<u32>("port");

Trait Implementations§

Source§

impl Debug for ParsedArgs

Source§

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

Formats the value using the given formatter. 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.