aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--day1/src/main.rs11
1 files changed, 5 insertions, 6 deletions
diff --git a/day1/src/main.rs b/day1/src/main.rs
index 778fc6d..2849be2 100644
--- a/day1/src/main.rs
+++ b/day1/src/main.rs
@@ -12,17 +12,16 @@ impl FromStr for Rotation {
type Err = ParseRotationError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
+ let err = || ParseRotationError(s.into());
+
let mut chars = s.chars();
- let lr = chars.next().ok_or_else(|| ParseRotationError(s.into()))?;
- let n: u16 = chars
- .collect::<String>()
- .parse()
- .map_err(|_| ParseRotationError(s.into()))?;
+ let lr = chars.next().ok_or_else(err)?;
+ let n: u16 = chars.collect::<String>().parse().map_err(|_| err())?;
match lr {
'L' => Ok(Self::Left(n)),
'R' => Ok(Self::Right(n)),
- _ => Err(ParseRotationError(s.into())),
+ _ => Err(err()),
}
}
}