ju-tcs-rust-23-29 0.1.0

function head and tail
Documentation
use std::fs::read_to_string;
use std::path::Path;

pub fn head(path: &Path, n: usize) -> Vec<String> {
    let mut lines: Vec<String> = Vec::new();
    lines = read_file(path);
    let size_file = lines.len();
    if size_file >= n {
        lines.drain(n.. size_file);
    } else {
        panic!("too few lines");
    }
    lines
}

pub fn tail(path: &Path, n: usize) -> Vec<String> {
    let mut lines: Vec<String> = Vec::new();
    lines = read_file(path);
    let size_file = lines.len();
    if size_file >= n {
        lines.drain(0.. size_file - n);
    } else {
        panic!("too few lines");
    }
    lines
}

fn read_file(path: &Path) -> Vec<String>{
    let mut lines: Vec<String> = Vec::new();
    for line in read_to_string(path).unwrap().lines(){
        lines.push(line.to_string());
    }
    lines
}