pub fn read_lines<'a>(
    input: &'a str,
    num_lines: usize,
) -> Result<(&'a str, Vec<&'a str>), Box<dyn Error>> {
    let mut counted_newlines = 0;
    let mut lines = Vec::with_capacity(num_lines);
    let mut prev_newline_index = 0;

    // count newline characters until we reach the amount of lines specified or we're through the whole string.
    for (index, c) in input.char_indices() {
        if c == '\n' {
            counted_newlines += 1;
            lines.push(&input[prev_newline_index..index]);
            prev_newline_index = index + 1;

            if counted_newlines == num_lines {
                break;
            }
        }
    }

    // if we had no newlines, treat the entire string as one big line. Otherwise, return the lines found.
    if prev_newline_index != 0 {
        let remainder = &input[prev_newline_index..];
        Ok((remainder, lines))
    } else {
        lines.push(&input[..]);
        Ok(("", lines))
    }
}
/// Parse lines from a string, returning the remaining string and a vec of lines
/// If there are no newlines in the string, it will assume the entire string is one line
/// as a workaround for how lines are dealt with in the diff module
Parse lines from a string, returning the remaining string and a vec of lines
If there are no newlines in the string, it will assume the entire string is one line
as a workaround for how lines are dealt with in the diff module
Parse lines from a string returning the remaining string and a vec of lines If there are no newlines in the string it will assume the entire string is one line as a workaround for how lines are dealt with in the diff module
pub fn read_lines<'a>(
    input: &'a str,
    num_lines: usize,
) -> Result<(&'a str, Vec<&'a str>), Box<dyn Error>> {
    let mut counted_newlines = 0;
    let mut lines = Vec::with_capacity(num_lines);
    let mut prev_newline_index = 0;
    // count newline characters until we reach the amount of lines specified or we're through the whole string.
    for (index, c) in input.char_indices() {
        if c == '\n' {
            counted_newlines += 1;
            lines.push(&input[prev_newline_index..index]);
            prev_newline_index = index + 1;
            if counted_newlines == num_lines {
                break;
            }
        }
    }
    // if we had no newlines, treat the entire string as one big line. Otherwise, return the lines found.
    if prev_newline_index != 0 {
        let remainder = &input[prev_newline_index..];
        Ok((remainder, lines))
    } else {
        lines.push(&input[..]);
        Ok(("", lines))
    }
}
pub fn read_lines < ' a > ( input : & ' a str , num_lines : usize , ) -> Result < ( & ' a str , Vec < & ' a str > ) , Box < dyn Error > > { let mut counted_newlines = 0 ; let mut lines = Vec :: with_capacity ( num_lines ) ; let mut prev_newline_index = 0 ; // count newline characters until we reach the amount of lines specified or we're through the whole string. for ( index , c ) in input . char_indices ( ) { if c == '\n' { counted_newlines += 1 ; lines . push ( & input [ prev_newline_index .. index ] ) ; prev_newline_index = index + 1 ; if counted_newlines == num_lines { break ; } } } // if we had no newlines, treat the entire string as one big line. Otherwise, return the lines found. if prev_newline_index != 0 { let remainder = & input [ prev_newline_index .. ] ; Ok ( ( remainder , lines ) ) } else { lines . push ( & input [ .. ] ) ; Ok ( ( " " , lines ) ) } }
Parse lines from a string, returning the remaining string and a vec of lines
If there are no newlines in the string, it will assume the entire string is one line
as a workaround for how lines are dealt with in the diff module
Parse lines from a string returning the remaining string and a vec of lines If there are no newlines in the string it will assume the entire string is one line as a workaround for how lines are dealt with in the diff module
input
&'a str
num_lines
usize
input
&'a str
num_lines
usize