Skip to main content

Argv

Struct Argv 

Source
pub struct Argv<'i> { /* private fields */ }
Expand description

A command line being parsed: the Stream every parser in this crate reads.

Its checkpoint is the whole state, so alt backtracking restores the Mode and the position inside a bundle along with the word.

Implementations§

Source§

impl<'i> Argv<'i>

Source

pub fn new(words: &'i [&'i BStr]) -> Self

Parse words, which should not include the program name.

Source

pub fn is_empty(&self) -> bool

Whether every word has been consumed.

Source

pub fn words_left(&self) -> usize

How many words are left, the current one included.

Source

pub fn mode(&self) -> Mode

Where in the grammar the stream is.

Source

pub fn stop_flags(&mut self)

Read every remaining word as a value, as if -- had been typed. An argument declared double_dash = "automatic" or stop_flags does this once it has a value.

Source

pub fn resume_flags(&mut self)

Recognize flags again after -- or Argv::stop_flags: a command’s restart_token starts a fresh invocation.

Source

pub fn offset(&self) -> usize

Byte offset from the start of the command line, one separator counted per word.

Source

pub fn front(&self) -> &'i [u8] ⓘ

The unread part of the current word; empty at the end.

Trait Implementations§

Source§

impl<'i> Clone for Argv<'i>

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<'i> Copy for Argv<'i>

Source§

impl Debug for Argv<'_>

Source§

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

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

impl<'i> Eq for Argv<'i>

Source§

impl<'i, E> FromExternalError<Argv<'i>, E> for Error
where E: Error + Send + Sync + 'static,

Lets try_map report a conversion failure. It backtracks, like any winnow error; the flag parsers in crate::combinator convert values themselves and commit, so their errors can name the flag.

Source§

fn from_external_error(input: &Argv<'i>, e: E) -> Self

Like ParserError::from_input but also include an external error.
Source§

impl Location for Argv<'_>

Source§

fn previous_token_end(&self) -> usize

Previous token’s end offset
Source§

fn current_token_start(&self) -> usize

Current token’s start offset
Source§

impl Offset for Argv<'_>

Source§

fn offset_from(&self, start: &Self) -> usize

Offset between the first byte of start and the first byte of selfa Read more
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<'i> ParserError<Argv<'i>> for Error

Source§

fn or(self, other: Self) -> Self

Keep whichever of the two says more: a specific failure beats a bare “did not match”, and otherwise the later branch wins, as in winnow.

Source§

type Inner = Error

Generally, Self Read more
Source§

fn from_input(input: &Argv<'i>) -> Self

Creates an error from the input position
Source§

fn is_backtrack(&self) -> bool

Is backtracking and trying new parse branches allowed?
Source§

fn into_inner(self) -> Result<Self::Inner, Self>

Unwrap the mode, returning the underlying error, if present
Source§

fn assert(input: &I, _message: &'static str) -> Self
where I: Debug,

Process a parser assertion
Source§

fn incomplete(input: &I, _needed: Needed) -> Self

There was not enough data to determine the appropriate action Read more
Source§

fn append(self, _input: &I, _token_start: &<I as Stream>::Checkpoint) -> Self

Like ParserError::from_input but merges it with the existing error. Read more
Source§

fn is_incomplete(&self) -> bool

Is more data Needed Read more
Source§

fn needed(&self) -> Option<Needed>

Extract the Needed data, if present Read more
Source§

impl<'i> PartialEq for Argv<'i>

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 SliceLen for Argv<'_>

Source§

fn slice_len(&self) -> usize

Calculates the input length, as indicated by its name, and the name of the trait itself
Source§

impl<'i> Stream for Argv<'i>

Tokens are words (the unread part of the current one first); slices are runs of whole words, so next_slice must not be asked to split a word.

Source§

type Token = &'i BStr

The smallest unit being parsed Read more
Source§

type Slice = &'i [&'i BStr]

Sequence of Tokens Read more
Source§

type IterOffsets = IterOffsets<'i>

Iterate with the offset from the current location
Source§

type Checkpoint = Argv<'i>

A parse location within the stream
Source§

fn iter_offsets(&self) -> Self::IterOffsets

Iterate with the offset from the current location
Source§

fn eof_offset(&self) -> usize

Returns the offset to the end of the input
Source§

fn next_token(&mut self) -> Option<Self::Token>

Split off the next token from the input
Source§

fn peek_token(&self) -> Option<Self::Token>

Split off the next token from the input
Source§

fn offset_for<P>(&self, predicate: P) -> Option<usize>
where P: Fn(Self::Token) -> bool,

Finds the offset of the next matching token
Source§

fn offset_at(&self, tokens: usize) -> Result<usize, Needed>

Get the offset for the number of tokens into the stream Read more
Source§

fn next_slice(&mut self, offset: usize) -> Self::Slice

Split off a slice of tokens from the input Read more
Source§

fn peek_slice(&self, offset: usize) -> Self::Slice

Split off a slice of tokens from the input
Source§

fn checkpoint(&self) -> Self::Checkpoint

Save the current parse location within the stream
Source§

fn reset(&mut self, checkpoint: &Self::Checkpoint)

Revert the stream to a prior Self::Checkpoint Read more
Source§

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

Write out a single-line summary of the current parse location
Source§

unsafe fn next_slice_unchecked(&mut self, offset: usize) -> Self::Slice

Split off a slice of tokens from the input Read more
Source§

unsafe fn peek_slice_unchecked(&self, offset: usize) -> Self::Slice

Split off a slice of tokens from the input Read more
Source§

fn finish(&mut self) -> Self::Slice

Advance to the end of the stream
Source§

fn peek_finish(&self) -> Self::Slice
where Self: Clone,

Advance to the end of the stream
Source§

impl StreamIsPartial for Argv<'_>

Source§

type PartialState = ()

Whether the stream is currently partial or complete
Source§

fn complete(&mut self) -> Self::PartialState

Mark the stream is complete
Source§

fn restore_partial(&mut self, _state: Self::PartialState)

Restore the stream back to its previous state
Source§

fn is_partial_supported() -> bool

Report whether the Stream is can ever be incomplete
Source§

fn is_partial(&self) -> bool

Report whether the Stream is currently incomplete
Source§

impl<'i> StructuralPartialEq for Argv<'i>

Auto Trait Implementations§

§

impl<'i> Freeze for Argv<'i>

§

impl<'i> RefUnwindSafe for Argv<'i>

§

impl<'i> Send for Argv<'i>

§

impl<'i> Sync for Argv<'i>

§

impl<'i> Unpin for Argv<'i>

§

impl<'i> UnsafeUnpin for Argv<'i>

§

impl<'i> UnwindSafe for Argv<'i>

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.