Skip to main content

Arg

Struct Arg 

Source
pub struct Arg {
    pub long: Option<&'static str>,
    pub short: Option<char>,
    pub negatable: bool,
    pub repeatable: bool,
    pub value_name: &'static str,
    pub position: Option<u16>,
}
Expand description

The argument-vector binding: the flag a value may arrive under.

How many values the flag takes is not declared here — it follows from the input’s crate::Type. A boolean flag takes none and means true by its presence; anything else takes exactly one. Deriving it removes a field that could contradict the type, and the derived arity is still written out explicitly in the published contract so no other language has to re-derive it.

Fields§

§long: Option<&'static str>

The long form without dashes, e.g. "log-level" for --log-level. Mutually exclusive with position — see Arg::positional.

§short: Option<char>

The short form without its dash, e.g. 'l' for -l. Mutually exclusive with position — see Arg::positional.

§negatable: bool

Whether --no-<long> is accepted to force the value off. Booleans only.

§repeatable: bool

Whether the flag may be repeated, accumulating values. Lists only.

§value_name: &'static str

The placeholder shown in help for the value, e.g. "LEVEL" in --log-level <LEVEL>. Ignored for booleans, which take no value.

§position: Option<u16>

A bare positional slot instead of a --flag, addressed by position rather than by name — see Arg::positional.

For an input with an empty crate::Input::subcommands list, this is the position among all positionals in the invocation (Some(0) is the first). For an input scoped to one or more subcommands, it is the position after the subcommand token itself — Some(0) is the first positional following the subcommand, letting two different subcommands each use their own Some(0) without conflict, since only one subcommand is ever active in a given invocation.

Implementations§

Source§

impl Arg

Source

pub const EMPTY: Arg

A binding with nothing set: Arg { long: Some("x"), ..Arg::EMPTY }.

Source

pub const fn long(long: &'static str) -> Arg

A long flag, e.g. Arg::long("log-level") for --log-level.

Source

pub const fn short(short: char) -> Arg

A short flag, e.g. Arg::short('l') for -l.

Source

pub const fn pair(long: &'static str, short: char) -> Arg

Both forms, e.g. Arg::pair("log-level", 'l').

Source

pub const fn positional(position: u16) -> Arg

A bare positional, e.g. Arg::positional(0) for the first one.

Not a --flag: consumed by position in argv, the same slot a resolver’s positionals list already collects (see argenv-resolve) — this lets a specific one be declared, typed, and documented like any other input.

Trait Implementations§

Source§

impl Clone for Arg

Source§

fn clone(&self) -> Arg

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for Arg

Source§

impl Debug for Arg

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Arg

§

impl RefUnwindSafe for Arg

§

impl Send for Arg

§

impl Sync for Arg

§

impl Unpin for Arg

§

impl UnsafeUnpin for Arg

§

impl UnwindSafe for Arg

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.