expression
Reject overlong text frames
Choose a maximum decoded line length before reading external data. An overlong line produces a codec error. The application must decide whether to disconnect or recover according to the codec contract. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): true Common mistake: Leaving line length unlimited because a queue has a bounded item count.
Formal Syntax & Structure
rust syntaxrust
LinesCodec::new_with_max_length(max_length)Working Example
Example Snippetrust
fn main() { use bytes::BytesMut; use tokio_util::codec::{Decoder, LinesCodec}; let mut c = LinesCodec::new_with_max_length(4); let mut b = BytesMut::from(&b"12345\n"[..]); println!("{}", c.decode(&mut b).is_err());}