std-method
Read::read_to_end: collect bytes
Append input bytes until the reader reports EOF and return the number newly read. This can use large memory or wait indefinitely on a continuous stream, so use bounds for untrusted inputs. Expected stdout (not executed): 2 abc Common mistake: Expecting an existing vector to be replaced.
Formal Syntax & Structure
rust syntaxrust
reader.read_to_end(&mut Vec<u8>) -> io::Result<usize>Working Example
Example Snippetrust
fn main() { use std::io::Read; let mut src = &b"bc"[..]; let mut data = vec![b'a']; let n = src.read_to_end(&mut data).unwrap(); println!("{n} {}", String::from_utf8(data).unwrap());}