std-method
Read::take: bound a reader
The adapter exposes at most a chosen number of bytes. This bounds input consumption but does not by itself prove the source ended or that a complete record was received. Expected stdout (not executed): abc def Common mistake: Treating the adapter reaching its limit as proof of real EOF.
Formal Syntax & Structure
rust syntaxrust
reader.take(limit: u64) -> Take<Self>Working Example
Example Snippetrust
fn main() { use std::io::Read; let mut src = &b"abcdef"[..]; let mut part = Vec::new(); (&mut src).take(3).read_to_end(&mut part).unwrap(); println!("{} {}", String::from_utf8(part).unwrap(), std::str::from_utf8(src).unwrap());}