mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Properly use TryFrom
This commit is contained in:
@@ -35,6 +35,20 @@ impl Pod {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TryFrom<usize> for Pod {
|
||||||
|
type Error = usize;
|
||||||
|
|
||||||
|
fn try_from(index: usize) -> Result<Self, Self::Error> {
|
||||||
|
match index {
|
||||||
|
0 => Ok(Pod::A),
|
||||||
|
1 => Ok(Pod::B),
|
||||||
|
2 => Ok(Pod::C),
|
||||||
|
3 => Ok(Pod::D),
|
||||||
|
_ => Err(index),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl TryFrom<char> for Pod {
|
impl TryFrom<char> for Pod {
|
||||||
type Error = &'static str;
|
type Error = &'static str;
|
||||||
|
|
||||||
@@ -107,13 +121,7 @@ impl<const S: usize> State<S> {
|
|||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(index, room)| {
|
.map(|(index, room)| {
|
||||||
let pod = match index {
|
let pod = Pod::try_from(index).unwrap();
|
||||||
0 => Pod::A,
|
|
||||||
1 => Pod::B,
|
|
||||||
2 => Pod::C,
|
|
||||||
3 => Pod::D,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
room.iter()
|
room.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
|
|||||||
Reference in New Issue
Block a user