std-module

std::io: input and output

I/O traits describe byte movement independently of where data lives. A memory slice can model input without opening a file; a vector can collect output. Operations can fail, so inspect Results. Expected stdout (not executed): tea Common mistake: Assuming all I/O requires files or a network.

Formal Syntax & Structure

rust syntaxrust
use std::io::{Read, Write};

Working Example

Example Snippetrust
fn main() {    use std::io::{Read, Write};    let mut input = &b"tea"[..];    let mut data = Vec::new();    input.read_to_end(&mut data).unwrap();    let mut output = Vec::new();    output.write_all(&data).unwrap();    println!("{}", String::from_utf8(output).unwrap());}
Rust Reference