pub struct PeekableBuffer<T>where
T: Clone,{ /* private fields */ }
Implementations§
Source§impl<T> PeekableBuffer<T>where
T: Clone,
impl<T> PeekableBuffer<T>where
T: Clone,
Sourcepub fn new<E>(elements: E) -> Self
pub fn new<E>(elements: E) -> Self
Creates a PeekableBuffer
object that owns all elements of &[T]
via cloning.
Sourcepub fn lookaround(&self, offset: i64) -> Option<&T>
pub fn lookaround(&self, offset: i64) -> Option<&T>
Returns a reference to the element offset
positions away from the
element currently being pointed to by the cursor. If the
computed offset is outside the bounds of the stream, None
is returned.
Sourcepub fn peek(&self) -> Option<&T>
pub fn peek(&self) -> Option<&T>
Returns a reference to the element just after the element currently
being pointed to by the cursor. This is equivalent to calling
lookaround(1)
.
Sourcepub fn current(&self) -> Option<&T>
pub fn current(&self) -> Option<&T>
Returns a reference to the element currently being pointed to by the
cursor. This is equivalent to calling lookaround(0)
.
Sourcepub fn shift(&mut self, offset: i64)
pub fn shift(&mut self, offset: i64)
Shifts the cursor by offset
positions. The computed offset
will be within the range [0, len()]
. If the computed offset is less
than 0, the cursor will point to the first element. If the
computed offset is greater than len() - 1
, the cursor will
point to the end and is_at_end()
returns true.
Sourcepub fn advance(&mut self)
pub fn advance(&mut self)
A convenience method that advances the cursor by 1. If the
stream is at the end, no action is taken. This is equivalent to calling
shift(1)
.
Sourcepub fn set_pos(&mut self, pos: usize) -> usize
pub fn set_pos(&mut self, pos: usize) -> usize
Sets the zero-indexed position of the cursor. If the
given pos
is outside of the range of the stream length, the
cursor will be set to len()
.
Sourcepub fn pos(&self) -> usize
pub fn pos(&self) -> usize
Returns the current zero-indexed position of the cursor. The
returned value is in the range [0, len()]
.
Sourcepub fn consume(&mut self) -> Option<&T>
pub fn consume(&mut self) -> Option<&T>
Returns a reference to the element currently being pointed to by the cursor, then advances the pointer by 1.
Sourcepub fn take_while<P>(&mut self, predicate: P) -> impl Iterator<Item = &T>
pub fn take_while<P>(&mut self, predicate: P) -> impl Iterator<Item = &T>
Returns an iterator containing elements that satisfy the given predicate, starting from the element currently pointed to by the stream pointer, up to either the end of the stream, or when the predicate returns fall, whichever comes first.
Sourcepub fn take(&mut self, n: usize) -> impl Iterator<Item = &T>
pub fn take(&mut self, n: usize) -> impl Iterator<Item = &T>
Returns an iterator containing all elements in the range
[pos(), pos() + n)
. The cursor will point to either the
end of the stream, or the element at pos() + n
, whichever is
first. If pos() + n
is outside the bounds of the stream, then
the rest of the stream is consumed and is_at_end()
returns true.
Sourcepub fn accept<P>(&self, predicate: P) -> bool
pub fn accept<P>(&self, predicate: P) -> bool
Returns true if the current element matches the given predicate, false otherwise. The function will return false if the stream is at the end regardless of the predicate.
Sourcepub fn slice_from(&self, from_inc: usize) -> PeekableBuffer<T>
pub fn slice_from(&self, from_inc: usize) -> PeekableBuffer<T>
Returns a new PeekableBuffer
containing all elements from the range
[from_inc, len() - 1]
, cloning the required elements into their
own iterable. If from_inc
is outside the range of the stream, an
empty PeekableBuffer
is returned.
Sourcepub fn slice_between(&self, from_inc: usize, to_exc: usize) -> PeekableBuffer<T>
pub fn slice_between(&self, from_inc: usize, to_exc: usize) -> PeekableBuffer<T>
Returns a new PeekableBuffer
containing all elements from the range
[from_inc, to_exc - 1]
, cloning the required elements into their
own iterable. If from_inc > to_exc
, this function will panic.
Otherwise, if from_inc
is greater than len()
, an empty
PeekableBuffer
is returned. If from_inc == to_exc
, an empty
PeekableBuffer
is returned as well.
Trait Implementations§
Source§impl<T> Clone for PeekableBuffer<T>
impl<T> Clone for PeekableBuffer<T>
Source§fn clone(&self) -> PeekableBuffer<T>
fn clone(&self) -> PeekableBuffer<T>
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read more