expression

FramedWrite sends encoded records

Use a sink to encode and send items to an asynchronous writer. Sending waits for a flush as part of the sink contract; it does not prove that a remote application processed the message. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): "ready\n" Common mistake: Treating successful local send as a remote acknowledgement.

Formal Syntax & Structure

rust syntaxrust
FramedWrite::new(writer, codec); SinkExt::send

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.send("ready").await.unwrap();    let b = w.into_inner();    println!("{:?}", String::from_utf8(b).unwrap());}
Rust Reference