From d9764b6b42a648daf3518166b4304bdac3f5c30e Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Tue, 23 Jun 2020 12:48:42 +0100 Subject: [PATCH] error for room type --- src/game.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/game.rs b/src/game.rs index bf37718..e66b1fb 100644 --- a/src/game.rs +++ b/src/game.rs @@ -33,12 +33,15 @@ impl RoomFormat { #[derive(Debug, Eq, PartialEq, Copy, Clone)] pub enum RoomType {Room, Set} -impl From<&str> for RoomType { - fn from(string: &str) -> RoomType { +#[derive(Debug)] +pub struct InvalidRoomType; + +impl RoomType { + fn from(string: &str) -> Result { match string { - "ROOM" => RoomType::Room, - "SET" => RoomType::Set, - _ => panic!("Unrecognised room type"), + "ROOM" => Ok(RoomType::Room), + "SET" => Ok(RoomType::Set), + _ => Err(InvalidRoomType), } } }