pub struct PipeBuf<T: 'static = u8> { /* private fields */ }
Expand description
Efficient byte-pipe buffer
This is the interface that is intended for use by the glue code.
Use PipeBuf::wr
to get a PBufWr
reference to write to the
buffer, and PipeBuf::rd
get a PBufRd
reference to read
from the buffer. These are the references that should be passed
to component code. See this crate’s top-level documentation for
further discussion of how this works.
Implementations§
source§impl<T: Copy + Default + 'static> PipeBuf<T>
impl<T: Copy + Default + 'static> PipeBuf<T>
sourcepub fn new() -> Self
Available on crate features std
and alloc
only.
pub fn new() -> Self
std
and alloc
only.Create a new empty pipe buffer
sourcepub fn with_capacity(cap: usize) -> Self
Available on crate features std
and alloc
only.
pub fn with_capacity(cap: usize) -> Self
std
and alloc
only.Create a new pipe buffer with the given initial capacity
sourcepub fn with_fixed_capacity(cap: usize) -> Self
Available on crate features std
and alloc
only.
pub fn with_fixed_capacity(cap: usize) -> Self
std
and alloc
only.Create a new pipe buffer with the given fixed capacity. The
buffer will never be reallocated. If a PBufWr::space
call
requests more space than is available, then the call will
panic.
sourcepub fn new_static(buffer: &'static mut [T]) -> Self
Available on crate feature static
only.
pub fn new_static(buffer: &'static mut [T]) -> Self
static
only.Create a new pipe buffer backed by the given static memory.
This is useful for no_std
without an allocator. This is a
safe call, but requires use of unsafe
in caller code because
the caller must guarantee that no other code is using this
static memory.
static mut BUF: [u8; 1024] = [0; 1024];
let _ = PipeBuf::new_static(unsafe { &mut *addr_of_mut!(BUF) });
sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the buffer to its initial state, i.e. in the Open
state and empty. The buffer backing memory is not zeroed, so
malicious code may observe old data in the slice returned by
PBufWr::space
. If sensitive data would be exposed in this
case, use PipeBuf::reset_and_zero
instead.
sourcepub fn reset_and_zero(&mut self)
pub fn reset_and_zero(&mut self)
Zero the buffer, and reset it to its initial state. If a
PipeBuf
is going to be kept in a pool and reused, it may be
best to zero it after use so that no sensitive data can leak
between different parts of the codebase.
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 is_push(&self) -> bool
pub fn is_push(&self) -> bool
Test whether the “push” state is set on the buffer without changing the state.
Trait Implementations§
source§impl<T: Copy + Default + 'static> Default for PipeBuf<T>
Available on crate features std
and alloc
only.
impl<T: Copy + Default + 'static> Default for PipeBuf<T>
std
and alloc
only.source§impl Read for PipeBuf<u8>
Available on crate feature std
only.
impl Read for PipeBuf<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 moresource§impl Write for PipeBuf<u8>
Available on crate feature std
only.
impl Write for PipeBuf<u8>
std
only.source§fn write(&mut self, data: &[u8]) -> Result<usize, Error>
fn write(&mut self, data: &[u8]) -> Result<usize, Error>
Write data to the pipe-buffer. Never returns an error. For variable-capacity, always succeeds. For fixed-capacity may panic in case more data is written than there is space available.
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)