Skip to main content

IoTest

Struct IoTest 

Source
pub struct IoTest { /* private fields */ }
Expand description

One endpoint of an in-memory asynchronous byte stream.

Use IoTest::create to construct connected client and server endpoints. Bytes written by one endpoint become readable from the other.

Implementations§

Source§

impl IoTest

Source

pub fn create() -> (IoTest, IoTest)

Creates connected client and server endpoints.

Source

pub fn is_client_dropped(&self) -> bool

Returns true after the client endpoint has been dropped.

Source

pub fn is_server_dropped(&self) -> bool

Returns true after the server endpoint has been dropped.

Source

pub fn is_closed(&self) -> bool

Returns true after the peer has closed its write side.

Source

pub fn set_peer_addr(self, addr: SocketAddr) -> Self

Sets the socket address returned by transport queries.

Source

pub fn read_pending(&self)

Forces subsequent reads from the peer endpoint to remain pending.

Source

pub fn read_error(&self, err: Error)

Makes the peer endpoint’s next read fail with err.

Source

pub fn write_error(&self, err: Error)

Makes the peer endpoint’s next transport write fail with err.

Source

pub fn write_zero(&self)

Makes the peer endpoint’s next transport write return zero bytes.

Source

pub fn local_buffer<F, R>(&self, f: F) -> R
where F: FnOnce(&mut BytesMut) -> R,

Provides mutable access to bytes readable by this endpoint.

Source

pub fn remote_buffer<F, R>(&self, f: F) -> R
where F: FnOnce(&mut BytesMut) -> R,

Provides mutable access to bytes readable by the peer endpoint.

Source

pub async fn close(&self)

Simulates this endpoint closing its write side.

This wakes the peer endpoint’s pending reader and waits briefly so the close can be observed by asynchronous test code.

Source

pub fn write<T: AsRef<[u8]>>(&self, data: T)

Writes bytes for the peer endpoint to read and wakes its reader.

Source

pub fn remote_buffer_cap(&self, cap: usize)

Sets how many bytes the peer may write before becoming blocked.

Increasing the capacity wakes the peer’s pending writer.

Source

pub fn read_any(&self) -> Bytes ⓘ

Takes all bytes currently readable by this endpoint without waiting.

Source

pub async fn read(&self) -> Result<Bytes, Error>

Waits for readable data or peer closure, then takes all available bytes.

Source

pub fn poll_read_buf( &self, cx: &mut Context<'_>, buf: &mut BytesMut, ) -> Poll<Result<usize>>

Polls a transport read into buf.

Returns the number of bytes copied, zero on simulated peer closure, or Pending when no input is available.

§Panics

Panics if data is available but buf has no remaining capacity.

Source

pub fn poll_write_buf( &self, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize>>

Polls a transport write from buf.

The write is limited by the capacity configured with remote_buffer_cap.

Trait Implementations§

Source§

impl Clone for IoTest

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for IoTest

Source§

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

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

impl Drop for IoTest

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl IoStream for IoTest

Source§

fn start(self, ctx: IoContext) -> Box<dyn Handle>

Starts transport-specific I/O tasks and returns their control handle.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.