Struct pipebuf::PBufRd

source ·
pub struct PBufRd<'a, T: 'static = u8> { /* private fields */ }
Expand description

Consumer reference to a PipeBuf

Obtain this reference using PipeBuf::rd. This is a mutable reference to a PipeBuf that exposes the calls that a consumer is allowed to use. It acts just like a &mut PipeBuf, and has the same size and efficiency. However unlike a &mut reference, reborrowing doesn’t happen automatically, but it can still be done just as efficiently using PBufRd::reborrow.

Implementations§

source§

impl<'a, T: Copy + Default + 'static> PBufRd<'a, T>

source

pub fn reborrow<'b, 'r>(&'r mut self) -> PBufRd<'b, T>
where 'a: 'b, 'r: 'b,

Create a new reference from this one, reborrowing it. Thanks to the borrow checker, the original reference will be inaccessible until the returned reference’s lifetime ends. The cost is just a pointer copy, just as for automatic &mut reborrowing.

source

pub fn tripwire(&self) -> PBufTrip

Obtain a tripwire value to detect buffer changes. See the PBufTrip type for further explanation.

source

pub fn is_tripped(&self, trip: PBufTrip) -> bool

Test whether there has been a change to the buffer since the tripwire value provided was obtained. See PBufTrip.

source

pub fn data(&self) -> &[T]

Get a reference to a slice of bytes representing the current contents of the buffer. If the consuming code is able to process any data, it should do so, and then indicate how many bytes have been consumed using PBufRd::consume.

source

pub fn data_mut(&mut self) -> &mut [T]

Get a mutable reference to a slice of bytes representing the current contents of the buffer. A mutable slice may be useful if the consuming code needs to modify the data in place during its processing. If the consuming code is able to process any data, it should do so, and then indicate how many bytes have been consumed using PBufRd::consume.

source

pub fn consume(&mut self, len: usize)

Indicate that len bytes should be marked as consumed from the start of the buffer. They will be discarded and will no longer be visible through this interface.

§Panics

Panics if len is greater than the number bytes in the buffer

source

pub fn len(&self) -> usize

Get the number of bytes held in the buffer

source

pub fn is_empty(&self) -> bool

Test whether the buffer is empty

source

pub fn consume_push(&mut self) -> bool

Try to consume a “push” indication from the stream. Returns true if a “push” was present and was consumed, and false if there was no “push” present.

source

pub fn consume_eof(&mut self) -> bool

Try to consume an EOF indication from the stream. This converts state Closing to Closed and Aborting to Aborted. Returns true if there was an EOF present waiting to be consumed and it was consumed, or false if there was no EOF indicated or if EOF was indicated but it was already consumed. The nature of the EOF consumed (close or abort) can be checked afterwards using PBufRd::is_aborted.

source

pub fn has_pending_eof(&self) -> bool

Test whether there is an end-of-file waiting to be consumed. This means a state of Closing or Aborting.

source

pub fn is_eof(&self) -> bool

Test whether end-of-file has been indicated by the producer. This means any of the states: Closing, Closed, Aborting or Aborted. In the case of EOF, then whatever unconsumed data is left in the buffer is the final data of the stream.

source

pub fn is_aborted(&self) -> bool

Test whether this stream has been aborted by the producer (states Aborting or Aborted)

source

pub fn is_done(&self) -> bool

Test whether an EOF has been indicated and consumed, and for the case of a Closed EOF also that the buffer is empty. This means that processing on this PipeBuf is complete

source

pub fn state(&self) -> PBufState

Get the current EOF/push state

source

pub fn forward(&mut self, dest: PBufWr<'_, T>)

Forward all the data found in this pipe to another pipe. Also forwards “push” and EOF indications.

source§

impl<'a> PBufRd<'a, u8>

source

pub fn output_to( &mut self, sink: &mut impl Write, force_flush: bool ) -> Result<()>

Available on crate feature std only.

Output as much data as possible to the given Write implementation. The “push” state is converted into a flush call if the pipe buffer is emptied. Also a flush can be forced if force_flush is set to true. End-of-file is not handled here as the Write trait does not support that. The calls are retried if ErrorKind::Interrupted is returned, but all other errors are returned directly.

You can use a tripwire (see PBufRd::tripwire) if you need to determine whether or not data was written. This is necessary because a call may both write data and return an error (for example WouldBlock).

Trait Implementations§

source§

impl<'a> Read for PBufRd<'a, u8>

Available on crate feature std only.
source§

fn read(&mut self, data: &mut [u8]) -> Result<usize, Error>

Read data from the pipe-buffer, as much as is available. The following returns are possible:

  • Ok(len): Some data was read
  • Ok(0): Successful end-of-file was reached
  • Err(e) with e.kind() == ErrorKind::WouldBlock: No data available right now
  • Err(e) with e.kind() == ErrorKind::ConnectionAborted: Aborted end-of-file was reached
1.36.0 · source§

fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>

Like read, except that it reads into a slice of buffers. Read more
source§

fn is_read_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
1.0.0 · source§

fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>

Read all bytes until EOF in this source, placing them into buf. Read more
1.0.0 · source§

fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>

Read all bytes until EOF in this source, appending them to buf. Read more
1.6.0 · source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Read the exact number of bytes required to fill buf. Read more
source§

fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
source§

fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>

🔬This is a nightly-only experimental API. (read_buf)
Read the exact number of bytes required to fill cursor. Read more
1.0.0 · source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adaptor for this instance of Read. Read more
1.0.0 · source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Transforms this Read instance to an Iterator over its bytes. Read more
1.0.0 · source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: Read, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
1.0.0 · source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more

Auto Trait Implementations§

§

impl<'a, T> Freeze for PBufRd<'a, T>

§

impl<'a, T> RefUnwindSafe for PBufRd<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for PBufRd<'a, T>
where T: Send,

§

impl<'a, T> Sync for PBufRd<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for PBufRd<'a, T>

§

impl<'a, T = u8> !UnwindSafe for PBufRd<'a, T>

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

§

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

§

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.