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
impl IoTest
Sourcepub fn is_client_dropped(&self) -> bool
pub fn is_client_dropped(&self) -> bool
Returns true after the client endpoint has been dropped.
Sourcepub fn is_server_dropped(&self) -> bool
pub fn is_server_dropped(&self) -> bool
Returns true after the server endpoint has been dropped.
Sourcepub fn set_peer_addr(self, addr: SocketAddr) -> IoTest
pub fn set_peer_addr(self, addr: SocketAddr) -> IoTest
Sets the socket address returned by transport queries.
Sourcepub fn read_pending(&self)
pub fn read_pending(&self)
Forces subsequent reads from the peer endpoint to remain pending.
Sourcepub fn read_error(&self, err: Error)
pub fn read_error(&self, err: Error)
Makes the peer endpoint’s next read fail with err.
Sourcepub fn write_error(&self, err: Error)
pub fn write_error(&self, err: Error)
Makes the peer endpoint’s next transport write fail with err.
Sourcepub fn write_zero(&self)
pub fn write_zero(&self)
Makes the peer endpoint’s next transport write return zero bytes.
Sourcepub fn local_buffer<F, R>(&self, f: F) -> R
pub fn local_buffer<F, R>(&self, f: F) -> R
Provides mutable access to bytes readable by this endpoint.
Sourcepub fn remote_buffer<F, R>(&self, f: F) -> R
pub fn remote_buffer<F, R>(&self, f: F) -> R
Provides mutable access to bytes readable by the peer endpoint.
Sourcepub async fn close(&self)
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.
Sourcepub fn write<T>(&self, data: T)
pub fn write<T>(&self, data: T)
Writes bytes for the peer endpoint to read and wakes its reader.
Sourcepub fn remote_buffer_cap(&self, cap: usize)
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.
Sourcepub fn read_any(&self) -> Bytes ⓘ
pub fn read_any(&self) -> Bytes ⓘ
Takes all bytes currently readable by this endpoint without waiting.
Sourcepub async fn read(&self) -> Result<Bytes, Error>
pub async fn read(&self) -> Result<Bytes, Error>
Waits for readable data or peer closure, then takes all available bytes.
Sourcepub fn poll_read_buf(
&self,
cx: &mut Context<'_>,
buf: &mut BytesMut,
) -> Poll<Result<usize, Error>>
pub fn poll_read_buf( &self, cx: &mut Context<'_>, buf: &mut BytesMut, ) -> Poll<Result<usize, Error>>
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.
Sourcepub fn poll_write_buf(
&self,
cx: &mut Context<'_>,
buf: &[u8],
) -> Poll<Result<usize, Error>>
pub fn poll_write_buf( &self, cx: &mut Context<'_>, buf: &[u8], ) -> Poll<Result<usize, Error>>
Polls a transport write from buf.
The write is limited by the capacity configured with
remote_buffer_cap.