std-function

io::empty: deterministic EOF

Construct a reader which immediately reports end of input. This helps test empty-source behavior without using the filesystem. Expected stdout (not executed): 0 [1] Common mistake: Mistaking an empty reader for a reader that produces zero-valued bytes.

Formal Syntax & Structure

rust syntaxrust
io::empty() -> Empty

Working Example

Example Snippetrust
fn main() {    use std::io::{self, Read};    let mut data = vec![1u8];    let n = io::empty().read_to_end(&mut data).unwrap();    println!("{n} {:?}", data);}
Rust Reference