Spec

Struct Spec 

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

Spec describes a flag, in such a way that the parser can correctly identify it in the set of arguments given on the command-line.

Implementations§

Source§

impl Spec

Source

pub fn required( name: &str, help: &str, short_name: Option<char>, default_value: Option<&str>, ) -> Spec

Constructs a Spec which describes a required named flag. This flag may have a default value, but the key point is that it must have some value after parsing is complete.

Source

pub fn optional(name: &str, help: &str, short_name: Option<char>) -> Spec

Constructs a Spec which describes an optional named flag. This flag may not have a value after we are finished parsing.

Source

pub fn boolean(name: &str, help: &str, short_name: Option<char>) -> Spec

Constructs a Spec which describes a boolean named flag. Flags of this type always have a value, and that value is either true or false, instead of being a freeform string like other flag types.

If this flag is not specified at all on the command line, its “default value” is false.

Source

pub fn positional( name: &str, help: &str, default_value: Option<&[&str]>, is_variadic: bool, ) -> Result<Spec>

Constructs a Spec which describes a positional flag. Flags of this type are not looked up by name after a “-” or “–” character, but instead are parsed purely by their position in the list of command-line arguments.

This also means that the order in which positional flags are added to a Specs structure matters for parsing.

A positional flag is variadic if it should be able to collect more than one value (e.g., for a command which takes a list of files to process of unspecified length).

Source

pub fn get_name(&self) -> &str

Returns this flag’s full name (i.e., not the short name).

Source

pub fn get_help(&self) -> &str

Returns the human-readable help text for this flag.

Source

pub fn get_short_name(&self) -> Option<char>

Returns this flag’s short name, if it has one.

Trait Implementations§

Source§

impl Clone for Spec

Source§

fn clone(&self) -> Spec

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Spec

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Spec

§

impl RefUnwindSafe for Spec

§

impl Send for Spec

§

impl Sync for Spec

§

impl Unpin for Spec

§

impl UnwindSafe for Spec

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> 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, 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.