Skip to main content

read_input

Function read_input 

Source
pub fn read_input(
    file: Option<&Path>,
    fallback: impl Read,
    max_lines: usize,
) -> Result<(Vec<String>, bool)>
Expand description

Read all lines from either a file path or the provided reader (typically stdin). Trailing \n/\r\n is stripped per line. A trailing empty line (from a terminating newline) is dropped.

Invalid UTF-8 bytes are replaced with U+FFFD REPLACEMENT CHARACTER rather than aborting the read — this matches grep’s behavior and keeps the filter usable against binary-ish logs (e.g. files with stray latin-1 bytes).

max_lines caps the number of lines read to prevent OOM on unbounded streams. Pass 0 to disable the cap. Returns (lines, truncated) where truncated is true if the cap was reached before end-of-input.