diff options
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 9 |
1 files changed, 9 insertions, 0 deletions
@@ -1,3 +1,6 @@ +use std::str::FromStr; +use std::fmt::Debug; + pub fn read_file(day: u8) -> String { let filename = format!("inputs/day{}", day); std::fs::read_to_string(filename).unwrap() @@ -8,3 +11,9 @@ pub fn read_lines(day: u8) -> Vec<String> { .map(String::from) .collect() } + +pub fn read_numbers<T: FromStr>(day: u8) -> Vec<T> where <T as FromStr>::Err: Debug { + read_lines(day).iter() + .map(|n| n.parse::<T>().unwrap()) + .collect::<Vec<T>>() +} |
