expression

Encode a line with a delimiter

The line encoder appends a newline. If a protocol forbids embedded line breaks, validate the payload yourself; a decoder length setting is not an output validation policy. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): [111, 107, 10] Common mistake: Assuming a line codec automatically rejects embedded newlines in an outgoing string.

Formal Syntax & Structure

rust syntaxrust
Encoder::encode(item, &mut buffer)

Working Example

Example Snippetrust
fn main() {    use bytes::BytesMut;    use tokio_util::codec::{Encoder, LinesCodec};    let mut c = LinesCodec::new_with_max_length(16);    let mut b = BytesMut::new();    c.encode("ok", &mut b).unwrap();    println!("{:?}", &b[..]);}
Rust Reference