pub struct Streaming<I>(pub I);
Expand description
Mark the input as a partial buffer for streaming input.
Complete input means that we already have all of the data. This will be the common case with small files that can be read entirely to memory.
In contrast, streaming input assumes that we might not have all of the data. This can happen with some network protocol or large file parsers, where the input buffer can be full and need to be resized or refilled.
Err::Incomplete
will report how much more data is needed.Parser::complete
transformErr::Incomplete
toErr::Error
See also InputIsStreaming
to tell whether the input supports complete or streaming parsing.
Example
Here is how it works in practice:
use nom8::{IResult, Err, Needed, error::{Error, ErrorKind}, bytes, character, input::Streaming};
fn take_streaming(i: Streaming<&[u8]>) -> IResult<Streaming<&[u8]>, &[u8]> {
bytes::take(4u8)(i)
}
fn take_complete(i: &[u8]) -> IResult<&[u8], &[u8]> {
bytes::take(4u8)(i)
}
// both parsers will take 4 bytes as expected
assert_eq!(take_streaming(Streaming(&b"abcde"[..])), Ok((Streaming(&b"e"[..]), &b"abcd"[..])));
assert_eq!(take_complete(&b"abcde"[..]), Ok((&b"e"[..], &b"abcd"[..])));
// if the input is smaller than 4 bytes, the streaming parser
// will return `Incomplete` to indicate that we need more data
assert_eq!(take_streaming(Streaming(&b"abc"[..])), Err(Err::Incomplete(Needed::new(1))));
// but the complete parser will return an error
assert_eq!(take_complete(&b"abc"[..]), Err(Err::Error(Error::new(&b"abc"[..], ErrorKind::Eof))));
// the alpha0 function recognizes 0 or more alphabetic characters
fn alpha0_streaming(i: Streaming<&str>) -> IResult<Streaming<&str>, &str> {
character::alpha0(i)
}
fn alpha0_complete(i: &str) -> IResult<&str, &str> {
character::alpha0(i)
}
// if there's a clear limit to the recognized characters, both parsers work the same way
assert_eq!(alpha0_streaming(Streaming("abcd;")), Ok((Streaming(";"), "abcd")));
assert_eq!(alpha0_complete("abcd;"), Ok((";", "abcd")));
// but when there's no limit, the streaming version returns `Incomplete`, because it cannot
// know if more input data should be recognized. The whole input could be "abcd;", or
// "abcde;"
assert_eq!(alpha0_streaming(Streaming("abcd")), Err(Err::Incomplete(Needed::new(1))));
// while the complete version knows that all of the data is there
assert_eq!(alpha0_complete("abcd"), Ok(("", "abcd")));
Tuple Fields
0: I
Implementations
sourceimpl<I> Streaming<I>
impl<I> Streaming<I>
sourcepub fn into_complete(self) -> I
pub fn into_complete(self) -> I
Convert to complete counterpart
Trait Implementations
sourceimpl<I, T> Compare<T> for Streaming<I>where
I: Compare<T>,
impl<I, T> Compare<T> for Streaming<I>where
I: Compare<T>,
sourcefn compare(&self, t: T) -> CompareResult
fn compare(&self, t: T) -> CompareResult
Compares self to another value for equality
sourcefn compare_no_case(&self, t: T) -> CompareResult
fn compare_no_case(&self, t: T) -> CompareResult
Compares self to another value for equality
independently of the case. Read more
sourceimpl<I> ExtendInto for Streaming<I>where
I: ExtendInto,
impl<I> ExtendInto for Streaming<I>where
I: ExtendInto,
type Item = <I as ExtendInto>::Item
type Item = <I as ExtendInto>::Item
The current input type is a sequence of that
Item
type. Read moretype Extender = <I as ExtendInto>::Extender
type Extender = <I as ExtendInto>::Extender
The type that will be produced
sourcefn new_builder(&self) -> Self::Extender
fn new_builder(&self) -> Self::Extender
Create a new
Extend
of the correct typesourcefn extend_into(&self, acc: &mut Self::Extender)
fn extend_into(&self, acc: &mut Self::Extender)
Accumulate the input into an accumulator
sourceimpl<I, T> FindSubstring<T> for Streaming<I>where
I: FindSubstring<T>,
impl<I, T> FindSubstring<T> for Streaming<I>where
I: FindSubstring<T>,
sourcefn find_substring(&self, substr: T) -> Option<usize>
fn find_substring(&self, substr: T) -> Option<usize>
Returns the byte position of the substring if it is found
sourceimpl<I, T> FindToken<T> for Streaming<I>where
I: FindToken<T>,
impl<I, T> FindToken<T> for Streaming<I>where
I: FindToken<T>,
sourcefn find_token(&self, token: T) -> bool
fn find_token(&self, token: T) -> bool
Returns true if self contains the token
sourceimpl<I> HexDisplay for Streaming<I>where
I: HexDisplay,
impl<I> HexDisplay for Streaming<I>where
I: HexDisplay,
sourceimpl<I> InputIsStreaming<true> for Streaming<I>where
I: InputIsStreaming<false>,
impl<I> InputIsStreaming<true> for Streaming<I>where
I: InputIsStreaming<false>,
sourceimpl<I> InputIter for Streaming<I>where
I: InputIter,
impl<I> InputIter for Streaming<I>where
I: InputIter,
sourcefn iter_indices(&self) -> Self::Iter
fn iter_indices(&self) -> Self::Iter
Returns an iterator over the elements and their byte offsets
sourcefn iter_elements(&self) -> Self::IterElem
fn iter_elements(&self) -> Self::IterElem
Returns an iterator over the elements
sourceimpl<I> InputLength for Streaming<I>where
I: InputLength,
impl<I> InputLength for Streaming<I>where
I: InputLength,
sourceimpl<I> InputTake for Streaming<I>where
I: InputTake,
impl<I> InputTake for Streaming<I>where
I: InputTake,
sourcefn take_split(&self, count: usize) -> (Self, Self)
fn take_split(&self, count: usize) -> (Self, Self)
Split the stream at the
count
byte offset. panics if count > lengthsourceimpl<I> InputTakeAtPosition for Streaming<I>where
I: InputTakeAtPosition,
impl<I> InputTakeAtPosition for Streaming<I>where
I: InputTakeAtPosition,
type Item = <I as InputTakeAtPosition>::Item
type Item = <I as InputTakeAtPosition>::Item
The current input type is a sequence of that
Item
type. Read moresourcefn split_at_position_complete<P, E>(
&self,
predicate: P
) -> IResult<Self, Self, E>where
P: Fn(Self::Item) -> bool,
E: ParseError<Self>,
fn split_at_position_complete<P, E>(
&self,
predicate: P
) -> IResult<Self, Self, E>where
P: Fn(Self::Item) -> bool,
E: ParseError<Self>,
Looks for the first element of the input type for which the condition returns true,
and returns the input up to this position. Read more
sourcefn split_at_position_streaming<P, E>(
&self,
predicate: P
) -> IResult<Self, Self, E>where
P: Fn(Self::Item) -> bool,
E: ParseError<Self>,
fn split_at_position_streaming<P, E>(
&self,
predicate: P
) -> IResult<Self, Self, E>where
P: Fn(Self::Item) -> bool,
E: ParseError<Self>,
Looks for the first element of the input type for which the condition returns true,
and returns the input up to this position. Read more
sourcefn split_at_position1_streaming<P, E>(
&self,
predicate: P,
kind: ErrorKind
) -> IResult<Self, Self, E>where
P: Fn(Self::Item) -> bool,
E: ParseError<Self>,
fn split_at_position1_streaming<P, E>(
&self,
predicate: P,
kind: ErrorKind
) -> IResult<Self, Self, E>where
P: Fn(Self::Item) -> bool,
E: ParseError<Self>,
Looks for the first element of the input type for which the condition returns true
and returns the input up to this position. Read more
sourcefn split_at_position1_complete<P, E>(
&self,
predicate: P,
kind: ErrorKind
) -> IResult<Self, Self, E>where
P: Fn(Self::Item) -> bool,
E: ParseError<Self>,
fn split_at_position1_complete<P, E>(
&self,
predicate: P,
kind: ErrorKind
) -> IResult<Self, Self, E>where
P: Fn(Self::Item) -> bool,
E: ParseError<Self>,
Looks for the first element of the input type for which the condition returns true
and returns the input up to this position. Read more
sourceimpl<I> IntoOutput for Streaming<I>where
I: IntoOutput,
impl<I> IntoOutput for Streaming<I>where
I: IntoOutput,
type Output = <I as IntoOutput>::Output
type Output = <I as IntoOutput>::Output
Output type
sourcefn into_output(self) -> Self::Output
fn into_output(self) -> Self::Output
Convert an
Input
into an appropriate Output
typesourcefn merge_output(self, inner: Self::Output) -> Self
fn merge_output(self, inner: Self::Output) -> Self
Convert an
Output
type to be used as Input
sourceimpl<I: Ord> Ord for Streaming<I>
impl<I: Ord> Ord for Streaming<I>
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<I: PartialEq> PartialEq<Streaming<I>> for Streaming<I>
impl<I: PartialEq> PartialEq<Streaming<I>> for Streaming<I>
sourceimpl<I: PartialOrd> PartialOrd<Streaming<I>> for Streaming<I>
impl<I: PartialOrd> PartialOrd<Streaming<I>> for Streaming<I>
sourcefn partial_cmp(&self, other: &Streaming<I>) -> Option<Ordering>
fn partial_cmp(&self, other: &Streaming<I>) -> Option<Ordering>
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<I: Copy> Copy for Streaming<I>
impl<I: Eq> Eq for Streaming<I>
impl<I> StructuralEq for Streaming<I>
impl<I> StructuralPartialEq for Streaming<I>
Auto Trait Implementations
impl<I> RefUnwindSafe for Streaming<I>where
I: RefUnwindSafe,
impl<I> Send for Streaming<I>where
I: Send,
impl<I> Sync for Streaming<I>where
I: Sync,
impl<I> Unpin for Streaming<I>where
I: Unpin,
impl<I> UnwindSafe for Streaming<I>where
I: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more