Skip to main content

VecTransport

Struct VecTransport 

Source
pub struct VecTransport {
    pub outgoing: VecDeque<u8>,
    pub incoming: VecDeque<u8>,
}
Expand description

In-memory loopback transport used in tests and the chaos bus.

Fields§

§outgoing: VecDeque<u8>

Bytes the caller has written and that are waiting to be drained by the peer (or by Self::take_outgoing).

§incoming: VecDeque<u8>

Bytes the peer has fed in and that the caller is yet to read.

Implementations§

Source§

impl VecTransport

Source

pub fn new() -> Self

New empty transport.

Source

pub fn feed(&mut self, bytes: &[u8])

Push bytes onto the read-side queue (simulates the peer).

Source

pub fn take_outgoing(&mut self) -> Vec<u8>

Drain the write-side queue.

Source

pub fn shuffle_to(&mut self, other: &mut VecTransport)

Move every byte from this transport’s outgoing queue into other’s incoming queue, modelling a one-way half-duplex bus segment. Useful in loopback tests and examples that wire two VecTransports back-to-back.

Trait Implementations§

Source§

impl Debug for VecTransport

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for VecTransport

Source§

fn default() -> VecTransport

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

impl Transport for VecTransport

Available on crate feature alloc only.
Source§

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

Send bytes in their entirety. The implementation must not return until either every byte is on the wire or an error has occurred.
Source§

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

Read up to buf.len() bytes. Read more
Source§

fn flush(&mut self) -> Result<(), Error>

Flush any internally-buffered bytes.

Auto Trait Implementations§

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.