Casting made easy
This commit is contained in:
		
					parent
					
						
							
								d35a92ed23
							
						
					
				
			
			
				commit
				
					
						fc49a2add1
					
				
			
		
					 1 changed files with 21 additions and 6 deletions
				
			
		|  | @ -31,12 +31,27 @@ impl Into<i32> for Play { | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| pub fn translate(letter: char) -> Option<Play> { | impl From<char> for Play { | ||||||
|     match letter { |     fn from(letter: char) -> Self { | ||||||
|         'A' => Some(Play::Rock), |         match letter { | ||||||
|         'B' => Some(Play::Paper), |             'A' => Play::Rock, | ||||||
|         'C' => Some(Play::Scissors), |             'B' => Play::Paper, | ||||||
|         _ => None, |             '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, | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue