expression

Observe EOF after draining a closed pipe

Dropping one endpoint lets its peer consume already buffered input and then observe EOF. It does not mean the buffered bytes disappear immediately. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): ok Common mistake: Discarding a receiver as soon as the producer closes, before draining data.

Formal Syntax & Structure

rust syntaxrust
drop(writer); reader.read(...).await

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() {    use tokio::io::{AsyncReadExt, AsyncWriteExt};    let (mut a, mut b) = tokio::io::duplex(8);    a.write_all(b"ok").await.unwrap();    drop(a);    let mut bytes = Vec::new();    b.read_to_end(&mut bytes).await.unwrap();    println!("{}", String::from_utf8(bytes).unwrap());}
Rust Reference