Struct tokio::io::DuplexStream
source · [−]pub struct DuplexStream { /* private fields */ }
Expand description
A bidirectional pipe to read and write bytes in memory.
A pair of DuplexStream
s are created together, and they act as a “channel”
that can be used as in-memory IO types. Writing to one of the pairs will
allow that data to be read from the other, and vice versa.
Example
let (mut client, mut server) = tokio::io::duplex(64);
client.write_all(b"ping").await?;
let mut buf = [0u8; 4];
server.read_exact(&mut buf).await?;
assert_eq!(&buf, b"ping");
server.write_all(b"pong").await?;
client.read_exact(&mut buf).await?;
assert_eq!(&buf, b"pong");
Trait Implementations
sourceimpl AsyncRead for DuplexStream
impl AsyncRead for DuplexStream
sourcefn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize>>
fn poll_read(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize>>
Attempts to read from the AsyncRead
into buf
. Read more
sourceunsafe fn prepare_uninitialized_buffer(
&self,
buf: &mut [MaybeUninit<u8>]
) -> bool
unsafe fn prepare_uninitialized_buffer(
&self,
buf: &mut [MaybeUninit<u8>]
) -> bool
Prepares an uninitialized buffer to be safe to pass to read
. Returns
true
if the supplied buffer was zeroed out. Read more
sourceimpl AsyncWrite for DuplexStream
impl AsyncWrite for DuplexStream
sourcefn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
fn poll_write(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize>>
Attempt to write bytes from buf
into the object. Read more
sourcefn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
Attempts to flush the object, ensuring that any buffered data reach their destination. Read more
sourceimpl Debug for DuplexStream
impl Debug for DuplexStream
Auto Trait Implementations
impl RefUnwindSafe for DuplexStream
impl Send for DuplexStream
impl Sync for DuplexStream
impl Unpin for DuplexStream
impl UnwindSafe for DuplexStream
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more