gix_packetline

Struct StreamingPeekableIter

source
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,

Non-IO methods

source

pub fn read_line(&mut self) -> Option<Result<Result<PacketLineRef<'_>, Error>>>

Available on crate feature 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
source

pub fn peek_line(&mut self) -> Option<Result<Result<PacketLineRef<'_>, Error>>>

Available on crate feature 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.

source

pub 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.

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.

source

pub fn as_read_without_sidebands<F: FnMut(bool, &[u8]) -> ProgressAction>( &mut self, ) -> WithSidebands<'_, T, F>

Available on crate feature 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().

source

pub fn as_read( &mut self, ) -> WithSidebands<'_, T, fn(_: bool, _: &[u8]) -> ProgressAction>

Available on crate feature 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>

source

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.

source

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)

source

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.

source

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.

source

pub fn reset_with(&mut self, delimiters: &'static [PacketLineRef<'static>])

Similar to reset() with support to changing the delimiters.

source

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

source

pub fn replace(&mut self, read: T) -> T

Replace the reader used with the given read, resetting all other iteration state as well.

source

pub fn into_inner(self) -> T

Return the inner read

Auto Trait Implementations§

§

impl<T> Freeze for StreamingPeekableIter<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for StreamingPeekableIter<T>
where T: RefUnwindSafe,

§

impl<T> Send for StreamingPeekableIter<T>
where T: Send,

§

impl<T> Sync for StreamingPeekableIter<T>
where T: Sync,

§

impl<T> Unpin for StreamingPeekableIter<T>
where T: Unpin,

§

impl<T> UnwindSafe for StreamingPeekableIter<T>
where T: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

source§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.