Write is the Rust standard-library trait used for byte-oriented output to a mutable sink. A TCP stream implements the role: the client writes bytes, and the server echoes them. section 2.2.2
Echo bytes over TCP
use std::io::{Read, Write}; let mut stream = TcpStream::connect("localhost:3000").unwrap(); stream.write("Hello".as_bytes()).unwrap(); let mut buffer = [0; 5]; stream.read(&mut buffer).unwrap();
Write an HTTP response
pub fn send_response(&self, write_stream: &mut impl Write) -> Result<()> { let response_string: String = String::from(self.clone()); let _ = write!(write_stream, "{}", response_string); Ok(()) }
