[][src]Struct dia_args::ReadOnlyArgs

pub struct ReadOnlyArgs { /* fields omitted */ }

Read-only Args

This struct is simply a read-only wrapper of Args.

Methods

impl ReadOnlyArgs[src]

pub const fn new(args: Args) -> Self[src]

Methods from Deref<Target = Args>

pub fn cmd(&self) -> Option<&str>[src]

Gets the command

This is simply the first one of args().

pub fn args(&self) -> Option<Vec<&str>>[src]

Gets arguments

If it's some vector, the vector is not empty.

The first one can be used as a command, via cmd().

pub fn options(&self) -> &HashMap<String, Vec<String>>[src]

Gets raw options

Normally you don't need this. Instead, you can use get(), get_vec()...

pub fn sub_args(&self) -> Option<Vec<&str>>[src]

Sub arguments

If it's some vector, the vector is not empty.

pub fn is_empty(&self) -> bool[src]

pub fn use_stdin(&self) -> bool[src]

pub fn get<T>(&self, keys: &[&str]) -> Result<Option<T>> where
    T: FromStr,
    <T as FromStr>::Err: Debug
[src]

Gets a value

You can provide multiple keys as you want. But the user can only provide one single key of them. This function can be used for short version and long version of your keys.

Examples

use dia_args;

let args = dia_args::parse_strings(["--type", "ogg"].iter())?;
assert_eq!(args.get::<String>(&["-t", "--type"])?.unwrap(), "ogg");

let args = dia_args::parse_strings(["--type", "ogg"].iter())?;
assert!(args.get::<String>(&["-t"])?.is_none());

let args = dia_args::parse_strings(["--type", "ogg", "-t", "some"].iter())?;
args.get::<String>(&["-t", "--type"]).unwrap_err();

pub fn get_vec<T>(&self, keys: &[&str]) -> Result<Option<Vec<T>>> where
    T: FromStr,
    <T as FromStr>::Err: Debug
[src]

Gets a vector of values

Examples

use dia_args;

let args = dia_args::parse_strings(
    ["--type", "ogg", "-t", "m4v", "--type", "md", "-t", "rs"].iter()
)?;
let mut types = args.get_vec::<String>(&["-t", "--type"])?.unwrap();
types.sort();
assert_eq!(types, &["m4v", "md", "ogg", "rs"]);

Trait Implementations

impl From<Args> for ReadOnlyArgs[src]

impl Clone for ReadOnlyArgs[src]

impl Deref for ReadOnlyArgs[src]

type Target = Args

The resulting type after dereferencing.

impl Debug for ReadOnlyArgs[src]

Auto Trait Implementations

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = !

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]