Struct Config

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

Specifies a configuration of parsed arguments Each option which was given as a spec can be accessed by option(name) This returns a Option<Vec> containing the values of the option (if any)

Implementations§

Source§

impl Config

Parses and generates configuration from supplied arguments and option specifications Can also generate usage strings

Source

pub fn new_env(specs: &[OptionSpec]) -> Result<Config, String>

Same as Config::new but uses the arguments passed to the program (env::args) The program path, first argument, is included in the unnamed args
Note, the spec isn’t stored with config

Source

pub fn new(args: &[&str], specs: &[OptionSpec]) -> Result<Config, String>

Parses config from custom supplied arguments
Specs is a list containing specifications for the available options a use can supply
Returns Err(msg) if a spec doesn’t match what is specified
The arguments before any option are specified with the (unnamed)
The values for the options can be accessed with the option(name) method
Parsing will fail if an option with policy other than Exact(0) is used twice Note, the spec isn’t stored with config

Source

pub fn generate_usage( specs: &[OptionSpec], list_required: bool, list_unrequired: bool, ) -> String

Generates a usage string from supplied specs

Source

pub fn command(&self) -> &String

Returns the command, I.e; the first argument

Source

pub fn option(&self, name: &str) -> Option<&[String]>

Returns the value[s] given to named or unnamed argument Returns None if argument didn’t exist

Auto Trait Implementations§

§

impl Freeze for Config

§

impl RefUnwindSafe for Config

§

impl Send for Config

§

impl Sync for Config

§

impl Unpin for Config

§

impl UnwindSafe for Config

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.