use std::{path::Path, fs::File};
use std::io::{self,BufRead};
pub fn head(path: &Path, n: usize) -> Vec<String> {
let file = File::open(path);
let lines = io::BufReader::new(file.unwrap()).lines();
let mut res: Vec<String> = vec![];
let mut i = n;
for line in lines {
if i == 0 { break; }
res.push(line.unwrap());
i -= 1;
}
res
}
pub fn tail(path: &Path, n: usize) -> Vec<String> {
let file = File::open(path);
let mut lines: Vec<Result<String,std::io::Error>> = io::BufReader::new(file.unwrap()).lines().collect();
lines.reverse();
let mut res: Vec<String> = vec![];
let mut i = n;
for line in lines {
if i == 0 { break; }
res.push( line.unwrap() );
i-=1;
}
res.reverse();
res
}
#[cfg(test)]
mod tests {
#[test]
fn test_math() {
assert_eq!(1 + 2, 3);
}
}