expression

Batch sink feed and flush

Feed accepts an item without requiring a final flush. Explicitly flush after the batch. Backpressure may cause writes before the explicit flush, so do not assume all data remains buffered until then. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): "a\nb\n" Common mistake: Dropping a buffered sink without flushing pending output.

Formal Syntax & Structure

rust syntaxrust
SinkExt::feed(item).await; SinkExt::flush().await

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() {    use futures_util::SinkExt;    use tokio_util::codec::{FramedWrite, LinesCodec};    let mut w = FramedWrite::new(Vec::new(), LinesCodec::new_with_max_length(16));    w.feed("a").await.unwrap();    w.feed("b").await.unwrap();    SinkExt::<&str>::flush(&mut w).await.unwrap();    println!("{:?}", String::from_utf8(w.into_inner()).unwrap());}
Rust Reference