expression
Create a private Unix stream pair
A connected pair transfers bytes locally without a filesystem socket name or TCP listener. A stream does not preserve application message boundaries. Use a known byte count for this tiny protocol; a production protocol needs bounded framing. Expected stdout (not executed): PONG Common mistake: Assuming one write equals one read. Run only in the isolated fixture runner, not a public code playground.
Formal Syntax & Structure
rust syntaxrust
UnixStream::pair() -> io::Result<(UnixStream, UnixStream)>Working Example
Example Snippetrust
use std::{io::{self,Read,Write}, os::unix::net::UnixStream};fn main() -> io::Result<()> { let (mut a,mut b) = UnixStream::pair()?; a.write_all(b"PING")?; let mut request=[0;4]; b.read_exact(&mut request)?; assert_eq!(&request,b"PING"); b.write_all(b"PONG")?; let mut response=[0;4]; a.read_exact(&mut response)?; println!("{}",std::str::from_utf8(&response).unwrap()); Ok(())}