add get nth line function

This commit is contained in:
Dietrich 2020-10-23 19:46:20 +02:00
parent 932fb2827d
commit d81bac5146

View File

@ -216,6 +216,15 @@ impl UserDBValidation for UserDBLocal {
} }
} }
fn get_nth_line(path: Option<&PathBuf>, n: u32) -> String {
let lines = file_to_string(path);
let line = lines.lines().nth(n as usize);
match line {
Some(line) => line.to_owned(),
None => "".to_owned(),
}
}
/// Parse a file to a string /// Parse a file to a string
fn file_to_string(path: Option<&PathBuf>) -> String { fn file_to_string(path: Option<&PathBuf>) -> String {
let file = File::open(path.expect("Path cannot be None".into())) let file = File::open(path.expect("Path cannot be None".into()))