std-method
Read::read_exact: fixed-size fields
Read a complete fixed-size field or return an error. UnexpectedEof signals a source that ends too early. A failed call does not promise an unchanged destination buffer. Expected stdout (not executed): true Common mistake: Decoding a field after read_exact failed.
Formal Syntax & Structure
rust syntaxrust
reader.read_exact(&mut [u8]) -> io::Result<()>Working Example
Example Snippetrust
fn main() { use std::io::Read; let mut source = &b"xy"[..]; let mut field = [0; 3]; let err = source.read_exact(&mut field).unwrap_err(); println!("{}", err.kind() == std::io::ErrorKind::UnexpectedEof);}