pub struct StreamingPeekableIter<T> { /* private fields */ }
Expand description
Read pack lines one after another, without consuming more than needed from the underlying
Read
. Flush
lines cause the reader to stop producing lines forever,
leaving Read
at the start of whatever comes next.
This implementation tries hard not to allocate at all which leads to quite some added complexity and plenty of extra memory copies.
Implementations§
Source§impl<T> StreamingPeekableIter<T>where
T: Read,
impl<T> StreamingPeekableIter<T>where
T: Read,
Non-IO methods
Sourcepub fn read_line(&mut self) -> Option<Result<Result<PacketLineRef<'_>, Error>>>
Available on crate feature blocking-io
only.
pub fn read_line(&mut self) -> Option<Result<Result<PacketLineRef<'_>, Error>>>
blocking-io
only.Read a packet line into the internal buffer and return it.
Returns None
if the end of iteration is reached because of one of the following:
- natural EOF
- ERR packet line encountered if
fail_on_err_lines()
is true. - A
delimiter
packet line encountered
Sourcepub fn peek_line(&mut self) -> Option<Result<Result<PacketLineRef<'_>, Error>>>
Available on crate feature blocking-io
only.
pub fn peek_line(&mut self) -> Option<Result<Result<PacketLineRef<'_>, Error>>>
blocking-io
only.Peek the next packet line without consuming it. Returns None
if a stop-packet or an error
was encountered.
Multiple calls to peek will return the same packet line, if there is one.
Sourcepub fn as_read_with_sidebands<F: FnMut(bool, &[u8]) -> ProgressAction>(
&mut self,
handle_progress: F,
) -> WithSidebands<'_, T, F> ⓘ
Available on crate feature blocking-io
only.
pub fn as_read_with_sidebands<F: FnMut(bool, &[u8]) -> ProgressAction>( &mut self, handle_progress: F, ) -> WithSidebands<'_, T, F> ⓘ
blocking-io
only.Return this instance as implementor of Read
assuming side bands to be used in all received packet lines.
Each invocation of read_line()
returns a packet line.
Progress or error information will be passed to the given handle_progress(is_error, text)
function, with is_error: bool
being true in case the text
is to be interpreted as error.
Please note that side bands need to be negotiated with the server.
Sourcepub fn as_read_without_sidebands<F: FnMut(bool, &[u8]) -> ProgressAction>(
&mut self,
) -> WithSidebands<'_, T, F> ⓘ
Available on crate feature blocking-io
only.
pub fn as_read_without_sidebands<F: FnMut(bool, &[u8]) -> ProgressAction>( &mut self, ) -> WithSidebands<'_, T, F> ⓘ
blocking-io
only.Same as as_read_with_sidebands(…)
, but for channels without side band support.
The type parameter F
needs to be configured for this method to be callable using the ‘turbofish’ operator.
Use as_read()
.
Sourcepub fn as_read(
&mut self,
) -> WithSidebands<'_, T, fn(_: bool, _: &[u8]) -> ProgressAction> ⓘ
Available on crate feature blocking-io
only.
pub fn as_read( &mut self, ) -> WithSidebands<'_, T, fn(_: bool, _: &[u8]) -> ProgressAction> ⓘ
blocking-io
only.Same as as_read_with_sidebands(…)
, but for channels without side band support.
Due to the preconfigured function type this method can be called without ‘turbofish’.
Source§impl<T> StreamingPeekableIter<T>
impl<T> StreamingPeekableIter<T>
Sourcepub fn new(
read: T,
delimiters: &'static [PacketLineRef<'static>],
trace: bool,
) -> Self
pub fn new( read: T, delimiters: &'static [PacketLineRef<'static>], trace: bool, ) -> Self
Return a new instance from read
which will stop decoding packet lines when receiving one of the given delimiters
.
If trace
is true
, all packetlines received or sent will be passed to the facilities of the gix-trace
crate.
Sourcepub fn peek_buffer_replace_and_truncate(
&mut self,
position: usize,
replace_with: u8,
)
pub fn peek_buffer_replace_and_truncate( &mut self, position: usize, replace_with: u8, )
Modify the peek buffer, overwriting the byte at position
with the given byte to replace_with
while truncating
it to contain only bytes until the newly replaced position
.
This is useful if you would want to remove ‘special bytes’ hidden behind, say a NULL byte to disappear and allow standard line readers to read the next line as usual.
Note that position
does not include the 4 bytes prefix (they are invisible outside the reader)
Sourcepub fn stopped_at(&self) -> Option<PacketLineRef<'static>>
pub fn stopped_at(&self) -> Option<PacketLineRef<'static>>
Returns the packet line that stopped the iteration, or
None
if the end wasn’t reached yet, on EOF, or if fail_on_err_lines()
was true.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset all iteration state allowing to continue a stopped iteration that is not yet at EOF.
This can happen once a delimiter is reached.
Sourcepub fn reset_with(&mut self, delimiters: &'static [PacketLineRef<'static>])
pub fn reset_with(&mut self, delimiters: &'static [PacketLineRef<'static>])
Similar to reset()
with support to changing the delimiters
.
Sourcepub fn fail_on_err_lines(&mut self, value: bool)
pub fn fail_on_err_lines(&mut self, value: bool)
If value
is true
the provider will check for special ERR
packet lines and stop iteration when one is encountered.
Use [stopped_at()]
StreamingPeekableIter::stopped_at()
to inspect the cause of the end of the iteration.
ne
Sourcepub fn replace(&mut self, read: T) -> T
pub fn replace(&mut self, read: T) -> T
Replace the reader used with the given read
, resetting all other iteration state as well.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Return the inner read