Skip to main content

## empty

# Function empty

const: 1.79.0 · Source

    pub const fn empty() -> Empty

🔬This is a nightly-only experimental API. (`alloc_io` #154046)
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());