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>

source

pub fn new() -> Self

Available on crate features std and alloc only.

Create a new empty bidirectional pipe

source

pub fn with_capacities(down_size: usize, up_size: usize) -> Self

Available on crate features std and alloc only.

Create a new bidirectional pipe buffer with the given initial capacity in the two directions

source

pub fn with_fixed_capacities(down_size: usize, up_size: usize) -> Self

Available on crate features 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.

source

pub fn new_static(down_buf: &'static mut [T], up_buf: &'static mut [T]) -> Self

Available on crate feature static only.

Create a new bidirectional pipe buffer backed by two regions of static memory

source

pub fn upper(&mut self) -> PBufRdWr<'_, T>

Get the references for reading and writing the stream from the “upper” end

source

pub fn lower(&mut self) -> PBufRdWr<'_, T>

Get the references for reading and writing the stream from the “lower” end

source

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.

source

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.

source

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.

source

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.

Trait Implementations§

source§

impl<T: Copy + Default + 'static> Default for PipeBufPair<T>

Available on crate features std and alloc only.
source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for PipeBufPair<T>

§

impl<T> RefUnwindSafe for PipeBufPair<T>
where T: RefUnwindSafe,

§

impl<T> Send for PipeBufPair<T>
where T: Send,

§

impl<T> Sync for PipeBufPair<T>
where T: Sync,

§

impl<T> Unpin for PipeBufPair<T>
where T: Unpin,

§

impl<T> UnwindSafe for PipeBufPair<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>,

§

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.