refact: remove unwrap() & panic!
This commit is contained in:
parent
953b5f451a
commit
ad157e1626
4 changed files with 177 additions and 52 deletions
|
|
@ -55,8 +55,12 @@ impl BoardGameBoard for TrictracBoard {
|
|||
|
||||
fn play(&mut self, mv: Self::Move) -> Result<(), PlayError> {
|
||||
self.check_can_play(mv)?;
|
||||
self.0.consume(&mv.to_event(&self.0).unwrap());
|
||||
Ok(())
|
||||
if let Some(evt) = mv.to_event(&self.0) {
|
||||
self.0.consume(&evt);
|
||||
Ok(())
|
||||
} else {
|
||||
Err(PlayError::UnavailableMove)
|
||||
}
|
||||
}
|
||||
|
||||
fn outcome(&self) -> Option<Outcome> {
|
||||
|
|
@ -159,9 +163,9 @@ impl InternalIterator for TrictracAvailableMovesIterator<'_> {
|
|||
where
|
||||
F: FnMut(Self::Item) -> ControlFlow<R>,
|
||||
{
|
||||
get_valid_actions(&self.board.0)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.try_for_each(f)
|
||||
match get_valid_actions(&self.board.0) {
|
||||
Ok(actions) => actions.into_iter().try_for_each(f),
|
||||
Err(_) => ControlFlow::Continue(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue