Skip to main content

ju_tcs_tbop_24_bebidek_endpoints/
lib.rs

1use std::{fs::read_to_string, io::Error, path::Path};
2
3pub fn head(path : &Path, n : usize) -> Result<Vec<String>,Error> {
4    let all_lines = read_into_vector(path)?;
5    Ok(all_lines[0..n.min(all_lines.len())].to_vec())
6}
7
8pub fn tail(path : &Path, n : usize) -> Result<Vec<String>,Error> {
9    let all_lines = read_into_vector(path)?;
10    Ok(all_lines[all_lines.len().saturating_sub(n)..].to_vec())
11}
12
13fn read_into_vector(path : &Path) -> Result<Vec<String>,Error> {
14    Ok(read_to_string(path)?.lines().map(String::from).collect())
15}