1
0
Fork 0
AdvenOfCode2022/src/prob2/mod.rs

44 lines
839 B
Rust

#[repr(u8)]
pub enum Play {
Rock,
Paper,
Scissors,
}
impl Into<char> for Play {
fn into(self) -> char {
match self {
Play::Rock => 'X',
Play::Paper => 'Y',
Play::Scissors => 'Z',
}
}
}
impl Into<i32> for Play {
fn into(self) -> i32 {
match self {
Play::Rock => 1,
Play::Paper => 2,
Play::Scissors => 3,
}
}
}
pub fn translate(letter: char) -> Option<Play> {
match letter {
'A' => Some(Play::Rock),
'B' => Some(Play::Paper),
'C' => Some(Play::Scissors),
_ => None,
}
}
pub fn winning(play: Play) -> char {
match play {
Play::Rock => Play::Paper.into(),
Play::Paper => Play::Scissors.into(),
Play::Scissors => Play::Rock.into(),
}
}