Hello,
I am trying to implement 'generic' string parser. Here is my code:
pub trait Solution {
type OutputPartOne: Display;
type OutputPartTwo: Display;
type Input: std::str::FromStr;
fn read_input(filename: &Path) -> Vec<Self::Input> {
let f = File::open(filename)
.expect(&format!("Could not open file at path {:?}!", filename));
let f = BufReader::new(f);
f.lines().filter_map(|l| l.ok()).map(|l| l.parse::<Self::Input>().unwrap()).collect()
}
Problem says:
method 'unwrap' not found in std::result::Result<<Self as puzzles::solution::Solution>::Input, <<Self as puzzles::solution::Solution>::Input as std::str::FromStr>::Err> | = note: the method unwrap exists but the following trait bounds were not satisfied: <<Self as puzzles::solution::Solution>::Input as std::str::FromStr>::Err: std::fmt::Debug
It seems like my 'Input' is not allowed to call 'unwrap' on. Could you help me with this one? The goal is to provide function parsing each line as integers, floats or just Strings (Depending on Input type).
thanks!