# Function empty

1.0.0 (const: 1.79.0) · Source

    pub const fn empty() -> Empty ⓘ

Expand description

Creates a value that is always at EOF for reads, and ignores all data written.

All calls to `write` on the returned instance will return `Ok(buf.len())` and the contents of the buffer will not be inspected.

All calls to `read` from the returned reader will return `Ok(0)`.

## §Examples

    use std::io::{self, Write};

    let buffer = vec![1, 2, 3, 5, 8];
    let num_bytes = io::empty().write(&buffer).unwrap();
    assert_eq!(num_bytes, 5);

    use std::io::{self, Read};

    let mut buffer = String::new();
    io::empty().read_to_string(&mut buffer).unwrap();
    assert!(buffer.is_empty());