/// Read the last `amount` lines of a file to a string.
///
/// TODO: This is super imperformant, but works as long as we don't use the last
/// 1000 lines. It would be cleaner to seek to the beginning of the requested
/// position and simply stream the content.
Read the last `amount` lines of a file to a string.
TODO: This is super imperformant, but works as long as we don't use the last
1000 lines. It would be cleaner to seek to the beginning of the requested
position and simply stream the content.
Read the last ` amount ` lines of a file to a string . TODO : This is super imperformant but works as long as we don ' t use the last 1000 lines . It would be cleaner to seek to the beginning of the requested position and simply stream the content .
pub fn read_last_lines(file: &mut File, amount: usize) -> String {
    // Read the lines from the file.
    // Return a debug string if it fails.
    let last_lines: Vec<String> = match rev_lines::RevLines::new(BufReader::new(file)) {
        Ok(lines) => lines.take(amount).collect(),
        Err(error) => return format!("(Pueue error) Failed to read last lines of file: {}", error),
    };
    last_lines
        .into_iter()
        .rev()
        .collect::<Vec<String>>()
        .join("\n")
}
pub fn read_last_lines ( file : & mut File , amount : usize ) -> String { // Read the lines from the file. // Return a debug string if it fails. let last_lines : Vec < String > = match rev_lines :: RevLines :: new ( BufReader :: new ( file ) ) { Ok ( lines ) => lines . take ( amount ) . collect ( ) , Err ( error ) => return format ! ( " " error ) , } ; last_lines . into_iter ( ) . rev ( ) . collect :: < Vec < String > > ( ) . join ( " \n " ) }
Read the last `amount` lines of a file to a string.
Read the last ` amount ` lines of a file to a string .
file
&mut File
amount
usize