diff options
Diffstat (limited to 'src/bin/day2.rs')
| -rw-r--r-- | src/bin/day2.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/bin/day2.rs b/src/bin/day2.rs index a007159..8c5c54d 100644 --- a/src/bin/day2.rs +++ b/src/bin/day2.rs @@ -1,9 +1,21 @@ #![feature(test)] +use std::str::FromStr; use std::error::Error; const COLORS: [&str; 3] = ["red", "green", "blue"]; const AMOUNT: [u32; 3] = [12, 13, 14]; +struct HelloWorld { + msg: String, +} + +impl FromStr for HelloWorld { + type Err = std::convert::Infallible; + fn from_str(s: &str) -> Result<Self, Self::Err> { + Ok(HelloWorld { msg: String::from(s), }) + } +} + // NOTE: probably should just panic, filter_mapping doesn't make much sense if you need the input to be correct. fn main() -> Result<(), Box<dyn Error>> { let file = std::fs::read_to_string("input/2/in.txt")?; @@ -61,6 +73,9 @@ fn main() -> Result<(), Box<dyn Error>> { .sum(); dbg!(part2); + let v: HelloWorld = "hi".parse()?; + println!("msg from impl: {}", v.msg); + Ok(()) } |
