Compare commits
No commits in common. "fc49a2add1c437f0d1f81d17a7588f9a8a5c448b" and "1e276e61ff59e29afbbbc22ea9c56d2004335e87" have entirely different histories.
fc49a2add1
...
1e276e61ff
3 changed files with 7 additions and 2528 deletions
|
@ -1,16 +1,10 @@
|
|||
#[derive(PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
pub enum Play {
|
||||
Rock,
|
||||
Paper,
|
||||
Scissors,
|
||||
}
|
||||
|
||||
enum ResultPlay {
|
||||
Win,
|
||||
Draw,
|
||||
Loss,
|
||||
}
|
||||
|
||||
impl Into<char> for Play {
|
||||
fn into(self) -> char {
|
||||
match self {
|
||||
|
@ -31,27 +25,12 @@ impl Into<i32> for Play {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<char> for Play {
|
||||
fn from(letter: char) -> Self {
|
||||
pub fn translate(letter: char) -> Option<Play> {
|
||||
match letter {
|
||||
'A' => Play::Rock,
|
||||
'B' => Play::Paper,
|
||||
'C' => Play::Scissors,
|
||||
'X' => Play::Rock,
|
||||
'Y' => Play::Paper,
|
||||
'Z' => Play::Scissors,
|
||||
_ => panic!("Only A, B, C, X, Y or Z letters are available."),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<i32> for ResultPlay {
|
||||
fn into(self) -> i32 {
|
||||
match self {
|
||||
ResultPlay::Win => 6,
|
||||
ResultPlay::Draw => 3,
|
||||
ResultPlay::Loss => 0,
|
||||
}
|
||||
'A' => Some(Play::Rock),
|
||||
'B' => Some(Play::Paper),
|
||||
'C' => Some(Play::Scissors),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue