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.