Skip to main content

read_capped_line

Function read_capped_line 

Source
pub fn read_capped_line<R: BufRead>(
    reader: &mut R,
    buf: &mut String,
    cap: usize,
) -> Result<CapOutcome>
Expand description

Read one line into buf, bounded to cap bytes.

buf is cleared first, then filled via a Read::take(cap + 1) ceiling so a hostile unterminated line is bounded before it can grow memory. The returned CapOutcome tells the caller whether a Line was read, the line was TooLarge, or input hit Eof; the caller maps that onto its own error type.