Skip to main content

read_bounded_line

Function read_bounded_line 

Source
pub async fn read_bounded_line<R: AsyncBufRead + Unpin>(
    reader: &mut R,
    line: &mut Vec<u8>,
    max_bytes: usize,
    ending: LineEnding,
) -> Result<Option<bool>>
Expand description

Read and drain one physical line, retaining at most max_bytes in line.

Clears and reuses the caller’s buffer. Returns None only at EOF without a line, and Some(truncated) for a complete or unterminated final line. Even with a zero-byte cap, a physical line is returned and drained. Oversized content is discarded through LF (or EOF), preserving the next frame boundary. This is byte framing: retained data need not end at a UTF-8 character boundary.

§Errors

Returns the underlying read error. After error or cancellation, callers must not assume the stream is aligned at a new line; this operation is not cancellation-safe and transports should terminate the reader on failure.