expression

Copy bytes between async endpoints

Transfer until EOF using a bounded internal working buffer and return the total byte count. The destination itself may grow without bound; use a limited reader or sink when the total input is untrusted. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 5 paper Common mistake: Assuming a bounded working buffer limits the total amount transferred.

Formal Syntax & Structure

rust syntaxrust
tokio::io::copy(&mut reader, &mut writer).await

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() {    let mut input = &b"paper"[..];    let mut out = Vec::new();    let n = tokio::io::copy(&mut input, &mut out).await.unwrap();    println!("{} {}", n, String::from_utf8(out).unwrap());}
Rust Reference