pub struct Stream<Input, X> {
pub input: Input,
pub positioner: X,
}
Expand description
The Stream<Input>
struct maintains the current position in the stream Input
using
the Positioner
trait to track the position.
let result = token(b'9')
.message("Not a nine")
.easy_parse(position::Stream::new(&b"8"[..]));
assert_eq!(result, Err(easy::Errors {
position: 0,
errors: vec![
easy::Error::Unexpected(b'8'.into()),
easy::Error::Expected(b'9'.into()),
easy::Error::Message("Not a nine".into())
]
}));
Fields§
§input: Input
The input stream used when items are requested
positioner: X
The positioner used to update the current position
Implementations§
Source§impl<Input, X> Stream<Input, X>
impl<Input, X> Stream<Input, X>
Sourcepub fn with_positioner(input: Input, positioner: X) -> Stream<Input, X>
pub fn with_positioner(input: Input, positioner: X) -> Stream<Input, X>
Creates a new Stream<Input, X>
from an input stream and a positioner.
Source§impl<Input> Stream<Input, Input::Positioner>
impl<Input> Stream<Input, Input::Positioner>
Sourcepub fn new(input: Input) -> Stream<Input, Input::Positioner>
pub fn new(input: Input) -> Stream<Input, Input::Positioner>
Creates a new Stream<Input, X>
from an input stream and its default positioner.
Trait Implementations§
Source§impl<Input, X, S> Positioned for Stream<Input, X>where
Input: StreamOnce,
X: Positioner<Input::Token>,
S: StreamError<Input::Token, Input::Range>,
Input::Error: ParseError<Input::Token, Input::Range, X::Position, StreamError = S> + ParseError<Input::Token, Input::Range, Input::Position, StreamError = S>,
impl<Input, X, S> Positioned for Stream<Input, X>where
Input: StreamOnce,
X: Positioner<Input::Token>,
S: StreamError<Input::Token, Input::Range>,
Input::Error: ParseError<Input::Token, Input::Range, X::Position, StreamError = S> + ParseError<Input::Token, Input::Range, Input::Position, StreamError = S>,
Source§impl<Input, X, S> RangeStreamOnce for Stream<Input, X>where
Input: RangeStreamOnce,
X: RangePositioner<Input::Token, Input::Range>,
S: StreamError<Input::Token, Input::Range>,
Input::Error: ParseError<Input::Token, Input::Range, X::Position, StreamError = S> + ParseError<Input::Token, Input::Range, Input::Position, StreamError = S>,
Input::Position: Clone + Ord,
impl<Input, X, S> RangeStreamOnce for Stream<Input, X>where
Input: RangeStreamOnce,
X: RangePositioner<Input::Token, Input::Range>,
S: StreamError<Input::Token, Input::Range>,
Input::Error: ParseError<Input::Token, Input::Range, X::Position, StreamError = S> + ParseError<Input::Token, Input::Range, Input::Position, StreamError = S>,
Input::Position: Clone + Ord,
Source§fn uncons_range(
&mut self,
size: usize,
) -> Result<Input::Range, StreamErrorFor<Self>>
fn uncons_range( &mut self, size: usize, ) -> Result<Input::Range, StreamErrorFor<Self>>
Takes
size
elements from the stream.
Fails if the length of the stream is less than size
.Source§fn uncons_while<F>(
&mut self,
predicate: F,
) -> Result<Input::Range, StreamErrorFor<Self>>
fn uncons_while<F>( &mut self, predicate: F, ) -> Result<Input::Range, StreamErrorFor<Self>>
Takes items from stream, testing each one with
predicate
.
returns the range of items which passed predicate
.Source§fn uncons_while1<F>(
&mut self,
predicate: F,
) -> ParseResult<Self::Range, StreamErrorFor<Self>>
fn uncons_while1<F>( &mut self, predicate: F, ) -> ParseResult<Self::Range, StreamErrorFor<Self>>
Takes items from stream, testing each one with
predicate
returns a range of at least one items which passed predicate
. Read moreSource§fn distance(&self, end: &Self::Checkpoint) -> usize
fn distance(&self, end: &Self::Checkpoint) -> usize
Source§impl<Input, X, S> ResetStream for Stream<Input, X>where
Input: ResetStream,
X: Positioner<Input::Token>,
S: StreamError<Input::Token, Input::Range>,
Input::Error: ParseError<Input::Token, Input::Range, X::Position, StreamError = S> + ParseError<Input::Token, Input::Range, Input::Position, StreamError = S>,
impl<Input, X, S> ResetStream for Stream<Input, X>where
Input: ResetStream,
X: Positioner<Input::Token>,
S: StreamError<Input::Token, Input::Range>,
Input::Error: ParseError<Input::Token, Input::Range, X::Position, StreamError = S> + ParseError<Input::Token, Input::Range, Input::Position, StreamError = S>,
type Checkpoint = Stream<<Input as ResetStream>::Checkpoint, <X as Positioner<<Input as StreamOnce>::Token>>::Checkpoint>
Source§fn checkpoint(&self) -> Self::Checkpoint
fn checkpoint(&self) -> Self::Checkpoint
Creates a
Checkpoint
at the current position which can be used to reset the stream
later to the current positionSource§impl<Input, X, S> StreamOnce for Stream<Input, X>where
Input: StreamOnce,
X: Positioner<Input::Token>,
S: StreamError<Input::Token, Input::Range>,
Input::Error: ParseError<Input::Token, Input::Range, X::Position, StreamError = S> + ParseError<Input::Token, Input::Range, Input::Position, StreamError = S>,
impl<Input, X, S> StreamOnce for Stream<Input, X>where
Input: StreamOnce,
X: Positioner<Input::Token>,
S: StreamError<Input::Token, Input::Range>,
Input::Error: ParseError<Input::Token, Input::Range, X::Position, StreamError = S> + ParseError<Input::Token, Input::Range, Input::Position, StreamError = S>,
Source§type Token = <Input as StreamOnce>::Token
type Token = <Input as StreamOnce>::Token
The type of items which is yielded from this stream.
Source§type Range = <Input as StreamOnce>::Range
type Range = <Input as StreamOnce>::Range
The type of a range of items yielded from this stream.
Types which do not a have a way of yielding ranges of items should just use the
Self::Token
for this type.Source§type Position = <X as Positioner<<Input as StreamOnce>::Token>>::Position
type Position = <X as Positioner<<Input as StreamOnce>::Token>>::Position
Type which represents the position in a stream.
Ord
is required to allow parsers to determine which of two positions are further ahead.type Error = <Input as StreamOnce>::Error
Source§fn uncons(&mut self) -> Result<Input::Token, StreamErrorFor<Self>>
fn uncons(&mut self) -> Result<Input::Token, StreamErrorFor<Self>>
Takes a stream and removes its first token, yielding the token and the rest of the elements.
Returns
Err
if no element could be retrieved.Source§fn is_partial(&self) -> bool
fn is_partial(&self) -> bool
Returns
true
if this stream only contains partial input. Read moreimpl<Input, X> StructuralPartialEq for Stream<Input, X>
Auto Trait Implementations§
impl<Input, X> Freeze for Stream<Input, X>
impl<Input, X> RefUnwindSafe for Stream<Input, X>where
Input: RefUnwindSafe,
X: RefUnwindSafe,
impl<Input, X> Send for Stream<Input, X>
impl<Input, X> Sync for Stream<Input, X>
impl<Input, X> Unpin for Stream<Input, X>
impl<Input, X> UnwindSafe for Stream<Input, X>where
Input: UnwindSafe,
X: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more