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>
impl<'a, T: Copy + Default + 'static> PBufRd<'a, T>
sourcepub fn reborrow<'b, 'r>(&'r mut self) -> PBufRd<'b, T>where
'a: 'b,
'r: 'b,
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.
sourcepub fn tripwire(&self) -> PBufTrip
pub fn tripwire(&self) -> PBufTrip
Obtain a tripwire value to detect buffer changes. See the
PBufTrip
type for further explanation.
sourcepub fn is_tripped(&self, trip: PBufTrip) -> bool
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
.
sourcepub fn data(&self) -> &[T]
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
.
sourcepub fn data_mut(&mut self) -> &mut [T]
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
.
sourcepub fn consume(&mut self, len: usize)
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
sourcepub fn consume_push(&mut self) -> bool
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.
sourcepub fn consume_eof(&mut self) -> bool
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
.
sourcepub fn has_pending_eof(&self) -> bool
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
.
sourcepub fn is_eof(&self) -> bool
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.
sourcepub fn is_aborted(&self) -> bool
pub fn is_aborted(&self) -> bool
Test whether this stream has been aborted by the producer
(states Aborting
or Aborted
)
source§impl<'a> PBufRd<'a, u8>
impl<'a> PBufRd<'a, u8>
sourcepub fn output_to(
&mut self,
sink: &mut impl Write,
force_flush: bool,
) -> Result<()>
Available on crate feature std
only.
pub fn output_to( &mut self, sink: &mut impl Write, force_flush: bool, ) -> Result<()>
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.
impl<'a> Read for PBufRd<'a, u8>
std
only.source§fn read(&mut self, data: &mut [u8]) -> Result<usize, Error>
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 readOk(0)
: Successful end-of-file was reachedErr(e)
withe.kind() == ErrorKind::WouldBlock
: No data available right nowErr(e)
withe.kind() == ErrorKind::ConnectionAborted
: Aborted end-of-file was reached
1.36.0 · source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize, Error>
read
, except that it reads into a slice of buffers. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize, Error>
buf
. Read more1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
buf
. Read more1.6.0 · source§fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
read_buf
)cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Read
. Read more