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>
impl<const N: usize> Named<N>
Sourcepub const fn long(self, name: &'static str) -> Named
pub const fn long(self, name: &'static str) -> Named
Answer to --name, replacing any long names.
Sourcepub const fn longs<const M: usize>(self, names: [&'static str; M]) -> Named<M>
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.
Sourcepub const fn allow_hyphen_values(self) -> Self
pub const fn allow_hyphen_values(self) -> Self
Take the next word as the value whatever it looks like: --args -x, --args --.
Sourcepub fn negated_by<'i, const M: usize>(
self,
no: Named<M>,
) -> impl Parser<Argv<'i>, bool, Error>
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”.
Sourcepub const fn require_equals(self) -> Self
pub const fn require_equals(self) -> Self
Only an attached value: --name=v, -cv; the next word is never taken.
Sourcepub const fn allow_negative_numbers(self) -> Self
pub const fn allow_negative_numbers(self) -> Self
Take a negative number as a detached value: --offset -1.
Sourcepub fn display(&self) -> String
pub fn display(&self) -> String
How to name the flag in a message: the long name if it has one.
Sourcepub fn missing(&self, input: &Argv<'_>) -> Error
pub fn missing(&self, input: &Argv<'_>) -> Error
The error for a required flag that never appeared.
Sourcepub fn argument<'i>(self) -> impl Parser<Argv<'i>, &'i BStr, Error>
pub fn argument<'i>(self) -> impl Parser<Argv<'i>, &'i BStr, Error>
An option taking one value, as bytes.
Sourcepub fn argument_as<'i, T: FromArg>(self) -> impl Parser<Argv<'i>, T, Error>
pub fn argument_as<'i, T: FromArg>(self) -> impl Parser<Argv<'i>, T, Error>
An option taking one value, converted with FromArg.
Sourcepub fn argument_or<'i, T: FromArg>(
self,
missing: &'static str,
) -> impl Parser<Argv<'i>, T, Error>
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.
Sourcepub fn argument_opt<'i>(self) -> impl Parser<Argv<'i>, Option<&'i BStr>, Error>
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.
Sourcepub fn argument_opt_as<'i, T: FromArg>(
self,
) -> impl Parser<Argv<'i>, Option<T>, Error>
pub fn argument_opt_as<'i, T: FromArg>( self, ) -> impl Parser<Argv<'i>, Option<T>, Error>
Named::argument_opt, converted with FromArg.
Trait Implementations§
impl<const N: usize> Copy for Named<N>
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.
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(
&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>,
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>,
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>,
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>,
Source§fn parse_peek(&mut self, input: I) -> Result<(I, O), E>
fn parse_peek(&mut self, input: I) -> Result<(I, O), E>
Source§fn by_ref(&mut self) -> ByRef<'_, Self, I, O, E>where
Self: Sized,
fn by_ref(&mut self) -> ByRef<'_, Self, I, O, E>where
Self: Sized,
&mut Self as a parser Read moreSource§fn default_value<O2>(self) -> DefaultValue<Self, I, O, O2, E>
fn default_value<O2>(self) -> DefaultValue<Self, I, O, O2, E>
Source§fn void(self) -> Void<Self, I, O, E>where
Self: Sized,
fn void(self) -> Void<Self, I, O, E>where
Self: Sized,
Parser Read moreSource§fn output_into<O2>(self) -> OutputInto<Self, I, O, O2, E>
fn output_into<O2>(self) -> OutputInto<Self, I, O, O2, E>
std::convert::From Read moreSource§fn with_taken(self) -> WithTaken<Self, I, O, E>
fn with_taken(self) -> WithTaken<Self, I, O, E>
Source§fn span(self) -> Span<Self, I, O, E>
fn span(self) -> Span<Self, I, O, E>
Source§fn with_span(self) -> WithSpan<Self, I, O, E>
fn with_span(self) -> WithSpan<Self, I, O, E>
Source§fn map<G, O2>(self, map: G) -> Map<Self, G, I, O, O2, E>
fn map<G, O2>(self, map: G) -> Map<Self, G, I, O, O2, E>
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>,
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>,
Result over the output of a parser. Read moreSource§fn verify_map<G, O2>(self, map: G) -> VerifyMap<Self, G, I, O, O2, E>
fn verify_map<G, O2>(self, map: G) -> VerifyMap<Self, G, I, O, O2, E>
Source§fn flat_map<G, H, O2>(self, map: G) -> FlatMap<Self, G, H, I, O, O2, E>
fn flat_map<G, H, O2>(self, map: G) -> FlatMap<Self, G, H, I, O, O2, E>
Source§fn parse_to<O2>(self) -> ParseTo<Self, I, O, O2, E>
fn parse_to<O2>(self) -> ParseTo<Self, I, O, O2, E>
std::str::FromStr to the output of the parser Read more