Skip to main content

Named

Struct Named 

Source
pub struct Named<const N: usize = 1> { /* private fields */ }
Expand description

The names a flag answers to: one short letter, and N long names (the first is the flag’s name, the rest are aliases).

N is part of the type so the common Named stays 24 bytes: the parsers built from it copy it on every use, and larger copies stall (docs/PERF.md, step 8). Only a flag with aliases pays for them.

Implementations§

Source§

impl<const N: usize> Named<N>

Source

pub const fn short(self, c: char) -> Self

Also answer to -c.

Source

pub const fn long(self, name: &'static str) -> Named

Answer to --name, replacing any long names.

Source

pub const fn longs<const M: usize>(self, names: [&'static str; M]) -> Named<M>

Answer to all of these long names, replacing any: the first is the flag’s name, the rest are aliases.

Source

pub const fn allow_hyphen_values(self) -> Self

Take the next word as the value whatever it looks like: --args -x, --args --.

Source

pub fn negated_by<'i, const M: usize>( self, no: Named<M>, ) -> impl Parser<Argv<'i>, bool, Error>

true for this flag, false for no, as in long("color").negated_by(long("no-color")). Fold with “last wins”.

Source

pub const fn require_equals(self) -> Self

Only an attached value: --name=v, -cv; the next word is never taken.

Source

pub const fn allow_negative_numbers(self) -> Self

Take a negative number as a detached value: --offset -1.

Source

pub fn matches(&self, arg: &Arg<'_>) -> bool

Whether arg is this flag.

Source

pub fn display(&self) -> String

How to name the flag in a message: the long name if it has one.

Source

pub fn missing(&self, input: &Argv<'_>) -> Error

The error for a required flag that never appeared.

Source

pub fn switch<'i>(self) -> impl Parser<Argv<'i>, (), Error>

A switch: --name or -c, no value.

Source

pub fn argument<'i>(self) -> impl Parser<Argv<'i>, &'i BStr, Error>

An option taking one value, as bytes.

Source

pub fn argument_as<'i, T: FromArg>(self) -> impl Parser<Argv<'i>, T, Error>

An option taking one value, converted with FromArg.

Source

pub fn argument_or<'i, T: FromArg>( self, missing: &'static str, ) -> impl Parser<Argv<'i>, T, Error>

An option whose value may be left out: a bare --name, or one followed by another flag, gives missing. --name=v and --name v give v.

Source

pub fn argument_opt<'i>(self) -> impl Parser<Argv<'i>, Option<&'i BStr>, Error>

An option whose value may be left off: a bare --name, or one followed by another flag, gives None. What an Option field holds.

Source

pub fn argument_opt_as<'i, T: FromArg>( self, ) -> impl Parser<Argv<'i>, Option<T>, Error>

Named::argument_opt, converted with FromArg.

Source

pub fn arguments_as<'i, T: FromArg>( self, delimiter: u8, ) -> impl Parser<Argv<'i>, Vec<T>, Error>

An option whose value is split on delimiter, each piece converted: --tags a,b gives two.

Trait Implementations§

Source§

impl<const N: usize> Clone for Named<N>

Source§

fn clone(&self) -> Self

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<const N: usize> Copy for Named<N>

Source§

impl<const N: usize> Debug for Named<N>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Eq for Named<N>

Source§

impl<'i, const N: usize> Parser<Argv<'i>, Arg<'i>, Error> for Named<N>

One occurrence of the flag’s name, value not yet read.

Source§

fn parse_next(&mut self, input: &mut Argv<'i>) -> Result<Arg<'i>, Error>

Take tokens from the Stream, turning it into the output Read more
Source§

fn parse( &mut self, input: I, ) -> Result<O, ParseError<I, <E as ParserError<I>>::Inner>>
where Self: Sized, I: Stream + StreamIsPartial, E: ParserError<I>, <E as ParserError<I>>::Inner: ParserError<I>,

Parse all of input, generating O from it Read more
Source§

fn parse_iter(&mut self, input: I) -> ParseIter<'_, Self, I, O, E> ⓘ
where Self: Sized, I: Stream + StreamIsPartial, E: ParserError<I>, <E as ParserError<I>>::Inner: ParserError<I>,

Repeat this parse until all of input is consumed, generating O from it Read more
Source§

fn parse_peek(&mut self, input: I) -> Result<(I, O), E>

Take tokens from the Stream, turning it into the output Read more
Source§

fn by_ref(&mut self) -> ByRef<'_, Self, I, O, E>
where Self: Sized,

Treat &mut Self as a parser Read more
Source§

fn value<O2>(self, val: O2) -> Value<Self, I, O, O2, E>
where Self: Sized, O2: Clone,

Produce the provided value Read more
Source§

fn default_value<O2>(self) -> DefaultValue<Self, I, O, O2, E>
where Self: Sized, O2: Default,

Produce a type’s default value Read more
Source§

fn void(self) -> Void<Self, I, O, E>
where Self: Sized,

Discards the output of the Parser Read more
Source§

fn output_into<O2>(self) -> OutputInto<Self, I, O, O2, E>
where Self: Sized, O: Into<O2>,

Convert the parser’s output to another type using std::convert::From Read more
Source§

fn take(self) -> Take<Self, I, O, E>
where Self: Sized, I: Stream,

Produce the consumed input as produced value. Read more
Source§

fn with_taken(self) -> WithTaken<Self, I, O, E>
where Self: Sized, I: Stream,

Produce the consumed input with the output Read more
Source§

fn span(self) -> Span<Self, I, O, E>
where Self: Sized, I: Stream + Location,

Produce the location of the consumed input as produced value. Read more
Source§

fn with_span(self) -> WithSpan<Self, I, O, E>
where Self: Sized, I: Stream + Location,

Produce the location of consumed input with the output Read more
Source§

fn map<G, O2>(self, map: G) -> Map<Self, G, I, O, O2, E>
where G: FnMut(O) -> O2, Self: Sized,

Maps a function over the output of a parser Read more
Source§

fn try_map<G, O2, E2>(self, map: G) -> TryMap<Self, G, I, O, O2, E, E2>
where Self: Sized, G: FnMut(O) -> Result<O2, E2>, I: Stream, E: FromExternalError<I, E2> + ParserError<I>,

Applies a function returning a Result over the output of a parser. Read more
Source§

fn verify_map<G, O2>(self, map: G) -> VerifyMap<Self, G, I, O, O2, E>
where Self: Sized, G: FnMut(O) -> Option<O2>, I: Stream, E: ParserError<I>,

Source§

fn flat_map<G, H, O2>(self, map: G) -> FlatMap<Self, G, H, I, O, O2, E>
where Self: Sized, G: FnMut(O) -> H, H: Parser<I, O2, E>,

Creates a parser from the output of this one Read more
Source§

fn parse_to<O2>(self) -> ParseTo<Self, I, O, O2, E>
where Self: Sized, I: Stream, O: ParseSlice<O2>, E: ParserError<I>,

Apply std::str::FromStr to the output of the parser Read more
Source§

fn verify<G, O2>(self, filter: G) -> Verify<Self, G, I, O, O2, E>
where Self: Sized, G: FnMut(&O2) -> bool, I: Stream, O: Borrow<O2>, E: ParserError<I>, O2: ?Sized,

Returns the output of the child parser if it satisfies a verification function. Read more
Source§

fn context<C>(self, context: C) -> Context<Self, I, O, E, C>
where Self: Sized, I: Stream, E: AddContext<I, C> + ParserError<I>, C: Clone + Debug,

If parsing fails, add context to the error Read more
Source§

fn context_with<F, C, FI>( self, context: F, ) -> ContextWith<Self, I, O, E, F, C, FI>
where Self: Sized, I: Stream, E: AddContext<I, C> + ParserError<I>, F: Fn() -> FI + Clone, C: Debug, FI: Iterator<Item = C>,

If parsing fails, dynamically add context to the error Read more
Source§

fn map_err<G, E2>(self, map: G) -> MapErr<Self, G, I, O, E, E2>
where G: FnMut(E) -> E2, Self: Sized,

Maps a function over the error of a parser Read more
Source§

fn complete_err(self) -> CompleteErr<Self, I, O, E>
where Self: Sized,

Source§

fn err_into<E2>(self) -> ErrInto<Self, I, O, E, E2>
where Self: Sized, E: Into<E2>,

Convert the parser’s error to another type using std::convert::From
Source§

impl<const N: usize> PartialEq for Named<N>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<const N: usize> StructuralPartialEq for Named<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Named<N>
where [Option<&'static str>; N]: Freeze,

§

impl<const N: usize> RefUnwindSafe for Named<N>
where [Option<&'static str>; N]: RefUnwindSafe,

§

impl<const N: usize> Send for Named<N>
where [Option<&'static str>; N]: Send,

§

impl<const N: usize> Sync for Named<N>
where [Option<&'static str>; N]: Sync,

§

impl<const N: usize> Unpin for Named<N>
where [Option<&'static str>; N]: Unpin,

§

impl<const N: usize> UnsafeUnpin for Named<N>
where [Option<&'static str>; N]: UnsafeUnpin,

§

impl<const N: usize> UnwindSafe for Named<N>
where [Option<&'static str>; N]: 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> 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.