Skip to main content

Args

Struct Args 

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

A builder for type-safe command arguments.

Implementations§

Source§

impl Args

Source

pub fn new() -> Self

Creates a new empty args builder.

Source

pub fn flag(self, short: &'static str, long: &'static str) -> Self

Adds a flag argument.

Source

pub fn optional_flag(self, short: &'static str, long: &'static str) -> Self

Adds an optional flag argument.

Source

pub fn option(self, short: &'static str, long: &'static str) -> Self

Adds an option argument (requires value).

Source

pub fn optional_option(self, short: &'static str, long: &'static str) -> Self

Adds an optional option argument.

Source

pub fn positional(self) -> Self

Adds a positional argument.

Source

pub fn optional_positional(self) -> Self

Adds an optional positional argument.

Source

pub fn value<V: AsRef<OsStr>>(self, value: V) -> Result<Self, String>

Sets the value for the last added argument that requires a value.

Sets the value for the last added argument that requires a value.

§Errors

Returns an error if no argument expects a value.

Source

pub fn build(self) -> Vec<OsString>

Builds the argument list as a vector of OsString.

Note: This consumes self. Use to_vec() for non-consuming access.

Source

pub fn validate(&self) -> Result<(), String>

Validates that all required arguments are provided.

§Errors

Returns an error if any required argument is missing.

Trait Implementations§

Source§

impl Debug for Args

Source§

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

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

impl Default for Args

Source§

fn default() -> Args

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

Auto Trait Implementations§

§

impl Freeze for Args

§

impl RefUnwindSafe for Args

§

impl Send for Args

§

impl Sync for Args

§

impl Unpin for Args

§

impl UnsafeUnpin for Args

§

impl UnwindSafe for Args

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.