expression

Read a known finite byte source

Append bytes until end of input. Use this convenience operation only when the source has a suitable size and termination bound. It may keep waiting on a connection that remains open. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 4 !pear Common mistake: Assuming read_to_end replaces existing buffer contents or finishes after one packet.

Formal Syntax & Structure

rust syntaxrust
reader.read_to_end(&mut Vec).await

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() {    use tokio::io::AsyncReadExt;    let mut input = &b"pear"[..];    let mut bytes = vec![b'!'];    let n = input.read_to_end(&mut bytes).await.unwrap();    println!("{} {}", n, String::from_utf8(bytes).unwrap());}
Rust Reference