Flag

Trait Flag 

Source
pub trait Flag: Default + Sealed { }
Expand description

Types that track the presence of a command-line flag without argument.

This trait is implemented for types that can be used with #[larpa(flag)] to either track the presence of, or count the number of times a command-line flag is specified.

This includes all built-in integer types and bool, but also Option<bool>, which will be None if the flag isn’t encountered at all, or Some if it is.

§Example

Accept a --verbose flag that can be specified multiple times:

use larpa::Command;

#[derive(Debug, PartialEq, Command)]
struct MyCmd {
    #[larpa(flag, name = ["--verbose", "-v"])]
    verbosity: u8,
}

assert_eq!(MyCmd::from_iter(["my-cmd"]), MyCmd { verbosity: 0 });
assert_eq!(MyCmd::from_iter(["my-cmd", "--verbose"]), MyCmd { verbosity: 1 });
assert_eq!(MyCmd::from_iter(["my-cmd", "-v"]), MyCmd { verbosity: 1 });
assert_eq!(MyCmd::from_iter(["my-cmd", "-vvv"]), MyCmd { verbosity: 3 });

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.

Implementations on Foreign Types§

Source§

impl Flag for Option<bool>

Source§

impl Flag for bool

Source§

impl Flag for i8

Source§

impl Flag for i16

Source§

impl Flag for i32

Source§

impl Flag for i64

Source§

impl Flag for i128

Source§

impl Flag for isize

Source§

impl Flag for u8

Source§

impl Flag for u16

Source§

impl Flag for u32

Source§

impl Flag for u64

Source§

impl Flag for u128

Source§

impl Flag for usize

Implementors§