Trait Arg

Source
pub trait Arg: Sized {
    type Item;
    type Error: Debug + Display;

Show 22 methods // Required methods fn update_switches<S: Switches>(&self, switches: &mut S); fn name(&self) -> String; fn get(self, matches: &Matches) -> Result<Self::Item, Self::Error>; // Provided methods fn validate(&self) -> Result<(), Invalid> { ... } fn parse_specified_ignoring_validation<I>( self, program_name: String, args: I, ) -> ParseResult<Self::Item, Self::Error> where I: IntoIterator, I::Item: AsRef<OsStr> { ... } fn parse_specified<I>( self, program_name: String, args: I, ) -> ParseResult<Self::Item, Self::Error> where I: IntoIterator, I::Item: AsRef<OsStr> { ... } fn parse_env(self) -> ParseResult<Self::Item, Self::Error> { ... } fn with_help(self, help_flag: Flag) -> WithHelp<Self> { ... } fn with_help_default(self) -> WithHelp<Self> { ... } fn option_map<F, T, U>(self, f: F) -> OptionMap<Self, F> where F: FnOnce(T) -> U { ... } fn with_default<T>(self, default_value: T) -> WithDefault<Self, T> { ... } fn with_default_lazy<F>( self, default_value_f: F, ) -> WithDefaultLazy<Self, F> { ... } fn choice<O>(self, other: O) -> Choice<Self, O> where O: Arg<Item = Self::Item> { ... } fn both<O>(self, other: O) -> Both<Self, O> where O: Arg { ... } fn map<F, U>(self, f: F) -> Map<Self, F> where F: FnOnce(Self::Item) -> U { ... } fn required(self) -> Required<Self> { ... } fn convert_string<F, T, E>(self, f: F) -> ConvertString<Self, F> where F: FnOnce(&str) -> Result<T, E> { ... } fn option_convert_string<F, T, E>( self, f: F, ) -> OptionConvertString<Self, F> where F: FnOnce(&str) -> Result<T, E> { ... } fn vec_convert_string<F, T, E>(self, f: F) -> VecConvertString<Self, F> where F: FnMut(&str) -> Result<T, E> { ... } fn vec_singleton(self) -> VecSingleton<Self> { ... } fn depend<O>(self, other: O) -> Depend<Self, O> where O: Arg { ... } fn some_if<T>(self, t: T) -> SomeIf<Self, T> { ... }
}

Required Associated Types§

Required Methods§

Source

fn update_switches<S: Switches>(&self, switches: &mut S)

Source

fn name(&self) -> String

Source

fn get(self, matches: &Matches) -> Result<Self::Item, Self::Error>

Provided Methods§

Source

fn validate(&self) -> Result<(), Invalid>

Source

fn parse_specified_ignoring_validation<I>( self, program_name: String, args: I, ) -> ParseResult<Self::Item, Self::Error>
where I: IntoIterator, I::Item: AsRef<OsStr>,

Source

fn parse_specified<I>( self, program_name: String, args: I, ) -> ParseResult<Self::Item, Self::Error>
where I: IntoIterator, I::Item: AsRef<OsStr>,

Source

fn parse_env(self) -> ParseResult<Self::Item, Self::Error>

Examples found in repository?
examples/hello.rs (line 9)
5fn main() {
6    match free::<String>()
7        .vec_singleton()
8        .required()
9        .parse_env()
10        .result
11    {
12        Ok(name) => println!("Hello, {}!", name),
13        Err(msg) => eprintln!("Error: {}", msg),
14    }
15}
More examples
Hide additional examples
examples/area.rs (line 11)
5fn main() {
6    match opt::<f32>("", "width", "", "")
7        .depend(opt::<f32>("", "height", "", ""))
8        .option_map(|(x, y)| (x, y))
9        .option_map(|(x, y)| x * y)
10        .required()
11        .parse_env()
12        .result
13    {
14        Ok(area) => println!("area: {:?}", area),
15        Err(e) => panic!("{}", e),
16    }
17}
Source

fn with_help(self, help_flag: Flag) -> WithHelp<Self>

Source

fn with_help_default(self) -> WithHelp<Self>

Examples found in repository?
examples/dimensions.rs (line 24)
23fn main() {
24    let dimensions = Dimensions::args().with_help_default().parse_env_or_exit();
25    println!("{:#?}", dimensions);
26}
Source

fn option_map<F, T, U>(self, f: F) -> OptionMap<Self, F>
where F: FnOnce(T) -> U,

Examples found in repository?
examples/area.rs (line 8)
5fn main() {
6    match opt::<f32>("", "width", "", "")
7        .depend(opt::<f32>("", "height", "", ""))
8        .option_map(|(x, y)| (x, y))
9        .option_map(|(x, y)| x * y)
10        .required()
11        .parse_env()
12        .result
13    {
14        Ok(area) => println!("area: {:?}", area),
15        Err(e) => panic!("{}", e),
16    }
17}
More examples
Hide additional examples
examples/dimensions.rs (line 17)
12    fn args() -> impl Arg<Item = Self> {
13        let window = args_depend! {
14            opt("", "width", "", ""),
15            opt("", "height", "", ""),
16        }
17        .option_map(|(width, height)| Dimensions::Window { width, height });
18        let fullscreen = flag("", "fullscreen", "").some_if(Dimensions::Fullscreen);
19        window.choice(fullscreen).required()
20    }
Source

fn with_default<T>(self, default_value: T) -> WithDefault<Self, T>

Source

fn with_default_lazy<F>(self, default_value_f: F) -> WithDefaultLazy<Self, F>

Source

fn choice<O>(self, other: O) -> Choice<Self, O>
where O: Arg<Item = Self::Item>,

Examples found in repository?
examples/dimensions.rs (line 19)
12    fn args() -> impl Arg<Item = Self> {
13        let window = args_depend! {
14            opt("", "width", "", ""),
15            opt("", "height", "", ""),
16        }
17        .option_map(|(width, height)| Dimensions::Window { width, height });
18        let fullscreen = flag("", "fullscreen", "").some_if(Dimensions::Fullscreen);
19        window.choice(fullscreen).required()
20    }
Source

fn both<O>(self, other: O) -> Both<Self, O>
where O: Arg,

Source

fn map<F, U>(self, f: F) -> Map<Self, F>
where F: FnOnce(Self::Item) -> U,

Source

fn required(self) -> Required<Self>

Examples found in repository?
examples/hello.rs (line 8)
5fn main() {
6    match free::<String>()
7        .vec_singleton()
8        .required()
9        .parse_env()
10        .result
11    {
12        Ok(name) => println!("Hello, {}!", name),
13        Err(msg) => eprintln!("Error: {}", msg),
14    }
15}
More examples
Hide additional examples
examples/area.rs (line 10)
5fn main() {
6    match opt::<f32>("", "width", "", "")
7        .depend(opt::<f32>("", "height", "", ""))
8        .option_map(|(x, y)| (x, y))
9        .option_map(|(x, y)| x * y)
10        .required()
11        .parse_env()
12        .result
13    {
14        Ok(area) => println!("area: {:?}", area),
15        Err(e) => panic!("{}", e),
16    }
17}
examples/dimensions.rs (line 19)
12    fn args() -> impl Arg<Item = Self> {
13        let window = args_depend! {
14            opt("", "width", "", ""),
15            opt("", "height", "", ""),
16        }
17        .option_map(|(width, height)| Dimensions::Window { width, height });
18        let fullscreen = flag("", "fullscreen", "").some_if(Dimensions::Fullscreen);
19        window.choice(fullscreen).required()
20    }
Source

fn convert_string<F, T, E>(self, f: F) -> ConvertString<Self, F>
where F: FnOnce(&str) -> Result<T, E>,

Source

fn option_convert_string<F, T, E>(self, f: F) -> OptionConvertString<Self, F>
where F: FnOnce(&str) -> Result<T, E>,

Source

fn vec_convert_string<F, T, E>(self, f: F) -> VecConvertString<Self, F>
where F: FnMut(&str) -> Result<T, E>,

Source

fn vec_singleton(self) -> VecSingleton<Self>

Examples found in repository?
examples/hello.rs (line 7)
5fn main() {
6    match free::<String>()
7        .vec_singleton()
8        .required()
9        .parse_env()
10        .result
11    {
12        Ok(name) => println!("Hello, {}!", name),
13        Err(msg) => eprintln!("Error: {}", msg),
14    }
15}
Source

fn depend<O>(self, other: O) -> Depend<Self, O>
where O: Arg,

Examples found in repository?
examples/area.rs (line 7)
5fn main() {
6    match opt::<f32>("", "width", "", "")
7        .depend(opt::<f32>("", "height", "", ""))
8        .option_map(|(x, y)| (x, y))
9        .option_map(|(x, y)| x * y)
10        .required()
11        .parse_env()
12        .result
13    {
14        Ok(area) => println!("area: {:?}", area),
15        Err(e) => panic!("{}", e),
16    }
17}
Source

fn some_if<T>(self, t: T) -> SomeIf<Self, T>

Examples found in repository?
examples/dimensions.rs (line 18)
12    fn args() -> impl Arg<Item = Self> {
13        let window = args_depend! {
14            opt("", "width", "", ""),
15            opt("", "height", "", ""),
16        }
17        .option_map(|(width, height)| Dimensions::Window { width, height });
18        let fullscreen = flag("", "fullscreen", "").some_if(Dimensions::Fullscreen);
19        window.choice(fullscreen).required()
20    }

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Arg for Flag

Source§

impl Arg for Free

Source§

impl Arg for Opt

Source§

impl<A> Arg for WithHelp<A>
where A: Arg,

Source§

type Item = OrHelp<<A as Arg>::Item>

Source§

type Error = <A as Arg>::Error

Source§

impl<A, B> Arg for Both<A, B>
where A: Arg, B: Arg,

Source§

type Item = (<A as Arg>::Item, <B as Arg>::Item)

Source§

type Error = BothError<<A as Arg>::Error, <B as Arg>::Error>

Source§

impl<A, B, T> Arg for Choice<A, B>
where A: Arg<Item = Option<T>>, B: Arg<Item = Option<T>>,

Source§

type Item = Option<T>

Source§

type Error = ChoiceError<<A as Arg>::Error, <B as Arg>::Error>

Source§

impl<A, F, T> Arg for WithDefaultLazy<A, F>
where A: Arg<Item = Option<T>>, F: FnOnce() -> T,

Source§

type Item = T

Source§

type Error = <A as Arg>::Error

Source§

impl<A, F, T, E> Arg for ConvertString<A, F>
where A: Arg<Item = String>, F: FnOnce(&str) -> Result<T, E>, E: Display + Debug,

Source§

impl<A, F, T, E> Arg for OptionConvertString<A, F>
where A: Arg<Item = Option<String>>, F: FnOnce(&str) -> Result<T, E>, E: Display + Debug,

Source§

impl<A, F, T, E> Arg for VecConvertString<A, F>
where A: Arg<Item = Vec<String>>, F: FnMut(&str) -> Result<T, E>, E: Display + Debug,

Source§

impl<A, F, T, U> Arg for OptionMap<A, F>
where A: Arg<Item = Option<T>>, F: FnOnce(T) -> U,

Source§

type Item = Option<U>

Source§

type Error = <A as Arg>::Error

Source§

impl<A, T> Arg for Required<A>
where A: Arg<Item = Option<T>>,

Source§

impl<A, T> Arg for SomeIf<A, T>
where A: Arg<Item = bool>,

Source§

type Item = Option<T>

Source§

type Error = <A as Arg>::Error

Source§

impl<A, T> Arg for VecSingleton<A>
where A: Arg<Item = Vec<T>>,

Source§

impl<A, T> Arg for WithDefault<A, T>
where A: Arg<Item = Option<T>>,

Source§

type Item = T

Source§

type Error = <A as Arg>::Error

Source§

impl<A, U, F> Arg for Map<A, F>
where A: Arg, F: FnOnce(A::Item) -> U,

Source§

type Item = U

Source§

type Error = <A as Arg>::Error

Source§

impl<T> Arg for Value<T>

Source§

impl<T, U, A, B> Arg for Depend<A, B>
where A: Arg<Item = Option<T>>, B: Arg<Item = Option<U>>,