Struct SimplexStream

pub struct SimplexStream { /* private fields */ }

A unidirectional pipe to read and write bytes in memory.

It can be constructed by simplex function which will create a pair of reader and writer or by calling SimplexStream::new_unsplit that will create a handle for both reading and writing.

Example

# async fn ex() -> std::io::Result<()> {
# use tokio::io::{AsyncReadExt, AsyncWriteExt};
let (mut receiver, mut sender) = tokio::io::simplex(64);

sender.write_all(b"ping").await?;

let mut buf = [0u8; 4];
receiver.read_exact(&mut buf).await?;
assert_eq!(&buf, b"ping");
# Ok(())
# }

Implementations

impl SimplexStream

fn new_unsplit(max_buf_size: usize) -> SimplexStream

Creates unidirectional buffer that acts like in memory pipe. To create split version with separate reader and writer you can use simplex function.

The max_buf_size argument is the maximum amount of bytes that can be written to a buffer before it returns Poll::Pending.

Trait Implementations

impl AsyncRead for SimplexStream

fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<Result<()>>

impl AsyncWrite for SimplexStream

fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>
fn poll_write_vectored(self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>]) -> Poll<Result<usize, Error>>
fn is_write_vectored(&self) -> bool
fn poll_flush(self: Pin<&mut Self>, &mut Context<'_>) -> Poll<Result<()>>
fn poll_shutdown(self: Pin<&mut Self>, &mut Context<'_>) -> Poll<Result<()>>

impl Debug for SimplexStream

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

Auto Trait Implementations

impl Freeze for SimplexStream

impl RefUnwindSafe for SimplexStream

impl Send for SimplexStream

impl Sync for SimplexStream

impl Unpin for SimplexStream

impl UnsafeUnpin for SimplexStream

impl UnwindSafe for SimplexStream

Blanket Implementations

impl<R> AsyncReadExt for SimplexStream where R: AsyncRead + ?Sized,

impl<T> Any for SimplexStream where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for SimplexStream where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for SimplexStream where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> From<T> for SimplexStream

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into<U> for SimplexStream where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

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

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for SimplexStream where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

impl<W> AsyncWriteExt for SimplexStream where W: AsyncWrite + ?Sized,