Struct pipebuf::PipeBufPair
source · pub struct PipeBufPair<T: 'static = u8> {
pub down: PipeBuf<T>,
pub up: PipeBuf<T>,
}
Expand description
A bidirectional pipe made up of two pipe buffers
Like a TCP stream, the two pipes are independent, and can be closed independently.
There are two calls to get producer/consumer references to the buffers, corresponding to the two ends of the bidirectional pipe, which are arbitrarily referred to as the “upper” and “lower” ends, or alternatively as the “left” and “right” ends, depending on how you wish to conceptualize things. Since pipes usually run between layers and layer diagrams are stacked vertically, it is hoped that upper/lower is the most helpful terminology, but left/right is offered as an alternative.
Fields§
§down: PipeBuf<T>
Downwards-flowing pipe
up: PipeBuf<T>
Upwards-flowing pipe
Implementations§
source§impl<T: Copy + Default + 'static> PipeBufPair<T>
impl<T: Copy + Default + 'static> PipeBufPair<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 bidirectional pipe
sourcepub fn with_capacities(down_size: usize, up_size: usize) -> Self
Available on crate features std
and alloc
only.
pub fn with_capacities(down_size: usize, up_size: usize) -> Self
std
and alloc
only.Create a new bidirectional pipe buffer with the given initial capacity in the two directions
sourcepub fn with_fixed_capacities(down_size: usize, up_size: usize) -> Self
Available on crate features std
and alloc
only.
pub fn with_fixed_capacities(down_size: usize, up_size: usize) -> Self
std
and alloc
only.Create a new bidirectional pipe buffer with the given fixed
capacity in the two directions. The buffers will never be
reallocated. If a PBufWr::space
call requests more space
than is available, then the call will panic.
sourcepub fn new_static(down_buf: &'static mut [T], up_buf: &'static mut [T]) -> Self
Available on crate feature static
only.
pub fn new_static(down_buf: &'static mut [T], up_buf: &'static mut [T]) -> Self
static
only.Create a new bidirectional pipe buffer backed by two regions of static memory
sourcepub fn upper(&mut self) -> PBufRdWr<'_, T>
pub fn upper(&mut self) -> PBufRdWr<'_, T>
Get the references for reading and writing the stream from the “upper” end
sourcepub fn lower(&mut self) -> PBufRdWr<'_, T>
pub fn lower(&mut self) -> PBufRdWr<'_, T>
Get the references for reading and writing the stream from the “lower” end
sourcepub fn left(&mut self) -> PBufRdWr<'_, T>
pub fn left(&mut self) -> PBufRdWr<'_, T>
Get the references for reading and writing the stream from the
“left” end. This is just a convenience to make code more
readable, and actually this is the same as
PipeBufPair::upper
.
sourcepub fn right(&mut self) -> PBufRdWr<'_, T>
pub fn right(&mut self) -> PBufRdWr<'_, T>
Get the references for reading and writing the stream from the
“right” end. This is just a convenience to make code more
readable, and actually this is the same as
PipeBufPair::lower
.
sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Reset the buffers to their initial state, i.e. in the Open
state and empty. The buffer backing memory is not zeroed.
sourcepub fn reset_and_zero(&mut self)
pub fn reset_and_zero(&mut self)
Zero the buffers, and reset them to their initial state. If a
PipeBufPair
is going to be kept in a pool and reused, it
should be zeroed after use so that no data can leak between
different parts of the codebase.