uj_tcs_rust_2023_13/
lib.rs

1use std::fs::read_to_string;
2
3pub fn head(path: String, n: usize) -> Vec<String>{
4    let mut result = Vec::new();
5    let mut i = 0;
6    for line in read_to_string(path).unwrap().lines() {
7        result.push(line.to_string());
8        i += 1;
9        if i == n{
10            break;
11        }
12    }
13
14    result
15}
16
17pub fn tail(path: String, n: usize) -> Vec<String>{
18    let mut result = Vec::new();
19    for line in read_to_string(path).unwrap().lines() {
20        result.push(line.to_string());
21    }
22    let r = result.as_slice()[result.len()-n..].to_vec();
23
24    r
25}
26
27
28