pub fn simplex(
max_buf_size: usize,
) -> (ReadHalf<SimplexStream>, WriteHalf<SimplexStream>)
Expand description
Creates unidirectional buffer that acts like in memory pipe.
The max_buf_size
argument is the maximum amount of bytes that can be
written to a buffer before the it returns Poll::Pending
.
ยงUnify reader and writer
The reader and writer half can be unified into a single structure
of SimplexStream
that supports both reading and writing or
the SimplexStream
can be already created as unified structure
using SimplexStream::new_unsplit()
.
let (writer, reader) = tokio::io::simplex(64);
let mut simplex_stream = writer.unsplit(reader);
simplex_stream.write_all(b"hello").await?;
let mut buf = [0u8; 5];
simplex_stream.read_exact(&mut buf).await?;
assert_eq!(&buf, b"hello");