Skip to main content

duplex

Function duplex 

Source
pub fn duplex(max_buf_size: usize) -> (DuplexStream, DuplexStream)
Expand description

Two connected in-memory streams, each direction a pipe of max_buf_size bytes: a write waits while its pipe is full.

use nuclei::io::{AsyncReadExt, AsyncWriteExt};

let (mut client, mut server) = nuclei::io::duplex(64);
client.write_all(b"ping").await.unwrap();
let mut buf = [0u8; 4];
server.read_exact(&mut buf).await.unwrap();
assert_eq!(&buf, b"ping");