devela::all

Function io_empty

1.0.0 (const: 1.79.0) · Source
pub const fn io_empty() -> Empty 
Available on crate feature std only.
Expand description

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

Re-exported from std::io:: emptyio_empty.


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());