summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Vink <ivi@vinkies.net>2023-12-14 22:39:58 +0100
committerMike Vink <ivi@vinkies.net>2023-12-14 22:39:58 +0100
commit6c741e79ebccc9ee6dd9595f24c09b41e2b234ba (patch)
tree7f0f0e4351508c5ddb4bcf3a2b284d2f6297766a /src
parent3ec662bbb1477be34fb14877fa4a549a6bb4bbf7 (diff)
fromstr trait huh
Diffstat (limited to 'src')
-rw-r--r--src/bin/day2.rs15
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(())
}