Skip to main content

read_line_capped

Function read_line_capped 

Source
pub async fn read_line_capped<R>(
    reader: &mut R,
    max_bytes: usize,
) -> Result<CappedLine>
where R: AsyncBufRead + Unpin,
Expand description

Read one newline-delimited line from reader, refusing to buffer more than max_bytes before the newline.

Unlike AsyncBufReadExt::read_line/lines(), a peer that streams bytes without ever sending \n cannot drive unbounded allocation here: once the pending line passes max_bytes the buffered bytes are dropped and we only scan forward for the next newline to resync.