From 96e9432f0615c555babec164b02c4cd1dd361e2a Mon Sep 17 00:00:00 2001 From: Max Bradbury Date: Tue, 23 Jun 2020 12:44:44 +0100 Subject: [PATCH] error for room format --- src/game.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/game.rs b/src/game.rs index ab86c53..bf37718 100644 --- a/src/game.rs +++ b/src/game.rs @@ -9,12 +9,15 @@ use std::str::FromStr; #[derive(Debug, Eq, PartialEq, Copy, Clone)] pub enum RoomFormat {Contiguous, CommaSeparated} +#[derive(Debug)] +pub struct InvalidRoomFormat; + impl RoomFormat { - fn from(str: &str) -> Result { + fn from(str: &str) -> Result { match str { "0" => Ok(RoomFormat::Contiguous), "1" => Ok(RoomFormat::CommaSeparated), - _ => panic!(format!("Invalid room format: {}", str)), + _ => Err(InvalidRoomFormat), } }