Struct ArgExt

Source
pub struct ArgExt<A> { /* private fields */ }

Implementations§

Source§

impl<A> ArgExt<A>
where A: Arg,

Source

pub fn result_map<F, U, E>(self, f: F) -> ArgExt<impl Arg<Item = U, Error = E>>
where E: Debug + Display, F: Fn(Result<A::Item, A::Error>) -> Result<U, E>,

Source

pub fn result_both<B>( self, b: B, ) -> ArgExt<impl Arg<Item = (Result<A::Item, A::Error>, Result<B::Item, B::Error>), Error = Never>>
where B: Arg, Self: Sized,

Source

pub fn both<B>( self, b: B, ) -> ArgExt<impl Arg<Item = (A::Item, B::Item), Error = BothError<A::Error, B::Error>>>
where B: Arg,

Source

pub fn try_map<F, U, E>( self, f: F, ) -> ArgExt<impl Arg<Item = U, Error = TryMapError<A::Error, E>>>
where E: Debug + Display, F: Fn(A::Item) -> Result<U, E>,

Source

pub fn map<F, U>(self, f: F) -> ArgExt<impl Arg<Item = U, Error = A::Error>>
where F: Fn(A::Item) -> U,

Examples found in repository?
examples/hello.rs (line 8)
6fn main() {
7    match free_str()
8        .map(|v| v.get(0).cloned())
9        .required()
10        .just_parse_env_default()
11    {
12        Ok(name) => println!("Hello, {}!", name),
13        Err(msg) => eprintln!("Error: {}", msg),
14    }
15}
Source

pub fn convert<F, U, E>( self, f: F, ) -> ArgExt<impl Arg<Item = U, Error = TryMapError<A::Error, ConvertFailed<A::Item, E>>>>
where A::Item: Clone + Debug + Display, E: Clone + Debug + Display, F: Fn(A::Item) -> Result<U, E>,

Source

pub fn with_help(self, flag: Flag) -> ArgExt<impl Arg<Item = HelpOr<A::Item>>>

Source

pub fn with_help_default(self) -> ArgExt<impl Arg<Item = HelpOr<A::Item>>>

Examples found in repository?
examples/dimensions.rs (line 25)
24fn main() {
25    match Dimensions::args().with_help_default().parse_env_default() {
26        (Ok(HelpOr::Value(dimensions)), _) => println!("{:#?}", dimensions),
27        (Ok(HelpOr::Help), usage) => println!("{}", usage.render()),
28        (Err(error), usage) => {
29            print!("{}\n\n", error);
30            print!("{}", usage.render());
31            ::std::process::exit(1);
32        }
33    }
34}
Source

pub fn rename( self, name: &str, ) -> ArgExt<impl Arg<Item = A::Item, Error = A::Error>>

Source

pub fn valid(self) -> Valid<A>

Source§

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

Source

pub fn depend<B, U>( self, b: B, ) -> ArgExt<impl Arg<Item = Option<(T, U)>, Error = DependError<A::Error, B::Error>>>
where B: Arg<Item = Option<U>>,

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        .just_parse_env_default()
12    {
13        Ok(area) => println!("area: {:?}", area),
14        Err(e) => panic!("{}", e),
15    }
16}
Source

pub fn otherwise<U>(self, b: U) -> ArgExt<impl Arg<Item = Either<T, U::Item>>>
where U: Arg,

Source

pub fn option_try_map<F, U, E>( self, f: F, ) -> ArgExt<impl Arg<Item = Option<U>, Error = TryMapError<A::Error, E>>>
where E: Debug + Display, F: Fn(T) -> Result<U, E>,

Source

pub fn option_map<F, U>( self, f: F, ) -> ArgExt<impl Arg<Item = Option<U>, Error = A::Error>>
where F: Fn(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        .just_parse_env_default()
12    {
13        Ok(area) => println!("area: {:?}", area),
14        Err(e) => panic!("{}", e),
15    }
16}
More examples
Hide additional examples
examples/dimensions.rs (line 18)
13    fn args() -> ArgExt<impl Arg<Item = Self>> {
14        let window =
15            args_all_depend! {
16                opt("", "width", "", ""),
17                opt("", "height", "", ""),
18            }.option_map(|(width, height)| Dimensions::Window { width, height });
19        let fullscreen = flag("", "fullscreen", "").some_if(Dimensions::Fullscreen);
20        window.either(fullscreen).required()
21    }
Source

pub fn either_or_both_any<B, U>( self, b: B, ) -> ArgExt<impl Arg<Item = Option<EitherOrBoth<T, U>>>>
where B: Arg<Item = Option<U>>,

Source

pub fn either_any<B, U>( self, b: B, ) -> ArgExt<impl Arg<Item = Option<Either<T, U>>>>
where B: Arg<Item = Option<U>>,

Source

pub fn either<B>(self, b: B) -> ArgExt<impl Arg<Item = Option<T>>>
where B: Arg<Item = Option<T>>,

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

pub fn with_default(self, t: T) -> ArgExt<impl Arg<Item = T>>
where T: Clone,

Source

pub fn required( self, ) -> ArgExt<impl Arg<Item = T, Error = TryMapError<A::Error, MissingRequiredArg>>>

Examples found in repository?
examples/hello.rs (line 9)
6fn main() {
7    match free_str()
8        .map(|v| v.get(0).cloned())
9        .required()
10        .just_parse_env_default()
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        .just_parse_env_default()
12    {
13        Ok(area) => println!("area: {:?}", area),
14        Err(e) => panic!("{}", e),
15    }
16}
examples/dimensions.rs (line 20)
13    fn args() -> ArgExt<impl Arg<Item = Self>> {
14        let window =
15            args_all_depend! {
16                opt("", "width", "", ""),
17                opt("", "height", "", ""),
18            }.option_map(|(width, height)| Dimensions::Window { width, height });
19        let fullscreen = flag("", "fullscreen", "").some_if(Dimensions::Fullscreen);
20        window.either(fullscreen).required()
21    }
Source

pub fn option_convert<F, U, E>( self, f: F, ) -> ArgExt<impl Arg<Item = Option<U>, Error = TryMapError<A::Error, ConvertFailed<T, E>>>>
where T: Clone + Debug + Display, E: Clone + Debug + Display, F: Fn(T) -> Result<U, E>,

Source§

impl<A> ArgExt<A>
where A: Arg<Item = bool>,

Source

pub fn some_if<T>(self, t: T) -> ArgExt<impl Arg<Item = Option<T>>>
where T: Clone,

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

pub fn unit_option(self) -> ArgExt<impl Arg<Item = Option<()>>>

Source

pub fn unless<U>(self, b: U) -> ArgExt<impl Arg<Item = Option<U::Item>>>
where U: Arg,

Source§

impl<A, I> ArgExt<A>
where A: Arg<Item = I>, I: IntoIterator,

Source

pub fn into_iter(self) -> ArgExt<impl Arg<Item = I::IntoIter>>

Source

pub fn vec_try_map<F, U, E>( self, f: F, ) -> ArgExt<impl Arg<Item = Vec<U>, Error = TryMapError<A::Error, E>>>
where E: Debug + Display, F: Fn(I::Item) -> Result<U, E>,

Source

pub fn vec_map<F, U>( self, f: F, ) -> ArgExt<impl Arg<Item = Vec<U>, Error = A::Error>>
where F: Fn(I::Item) -> U,

Source

pub fn vec_convert<F, U, E>( self, f: F, ) -> ArgExt<impl Arg<Item = Vec<U>, Error = TryMapError<A::Error, ConvertFailed<I::Item, E>>>>
where I::Item: Clone + Debug + Display, E: Clone + Debug + Display, F: Fn(I::Item) -> Result<U, E>,

Source§

impl<A, I, T, E> ArgExt<A>
where E: Debug + Display, A: Arg<Item = I>, I: IntoIterator<Item = Result<T, E>>,

Source

pub fn vec_ok_or_first_err( self, ) -> ArgExt<impl Arg<Item = Vec<T>, Error = TryMapError<A::Error, E>>>

Source§

impl<A, I> ArgExt<A>
where A: Arg<Item = I>, I: Iterator,

Source

pub fn collect<C>(self) -> ArgExt<impl Arg<Item = C>>
where C: FromIterator<I::Item>,

Trait Implementations§

Source§

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

Source§

type Item = <A as Arg>::Item

Source§

type Error = <A as Arg>::Error

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>

Source§

fn parse<I>( &self, args: I, ) -> (Result<Self::Item, TopLevelError<Self::Error>>, Usage)
where I: IntoIterator, I::Item: AsRef<OsStr>,

Source§

fn validate(&self) -> Option<Invalid>

Source§

fn parse_env( &self, program_name: ProgramName, ) -> (Result<Self::Item, TopLevelError<Self::Error>>, UsageWithProgramName)

Source§

fn parse_env_default( &self, ) -> (Result<Self::Item, TopLevelError<Self::Error>>, UsageWithProgramName)

Source§

fn just_parse<I>( &self, args: I, ) -> Result<Self::Item, TopLevelError<Self::Error>>
where I: IntoIterator, I::Item: AsRef<OsStr>,

Source§

fn just_parse_env( &self, program_name: ProgramName, ) -> Result<Self::Item, TopLevelError<Self::Error>>

Source§

fn just_parse_env_default( &self, ) -> Result<Self::Item, TopLevelError<Self::Error>>

Auto Trait Implementations§

§

impl<A> Freeze for ArgExt<A>
where A: Freeze,

§

impl<A> RefUnwindSafe for ArgExt<A>
where A: RefUnwindSafe,

§

impl<A> Send for ArgExt<A>
where A: Send,

§

impl<A> Sync for ArgExt<A>
where A: Sync,

§

impl<A> Unpin for ArgExt<A>
where A: Unpin,

§

impl<A> UnwindSafe for ArgExt<A>
where A: UnwindSafe,

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.