expression
Close a framed sink explicitly
Close the sink according to its contract, flushing buffered output and shutting down the underlying writer where supported. Closing is not an application-level acknowledgement. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): done true Common mistake: Dropping a pending send and claiming the peer received a complete message.
Formal Syntax & Structure
rust syntaxrust
SinkExt::<Item>::close(&mut sink).awaitWorking Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { use futures_util::{SinkExt, StreamExt}; use tokio_util::codec::{FramedRead, FramedWrite, LinesCodec}; let (a, b) = tokio::io::duplex(64); let mut w = FramedWrite::new(a, LinesCodec::new_with_max_length(16)); let mut r = FramedRead::new(b, LinesCodec::new_with_max_length(16)); w.feed("done").await.unwrap(); SinkExt::<&str>::close(&mut w).await.unwrap(); println!("{}", r.next().await.unwrap().unwrap()); println!("{}", r.next().await.is_none());}