error for room format

This commit is contained in:
Max Bradbury 2020-06-23 12:44:44 +01:00
parent edbf9575d7
commit 96e9432f06
1 changed files with 5 additions and 2 deletions

View File

@ -9,12 +9,15 @@ use std::str::FromStr;
#[derive(Debug, Eq, PartialEq, Copy, Clone)] #[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum RoomFormat {Contiguous, CommaSeparated} pub enum RoomFormat {Contiguous, CommaSeparated}
#[derive(Debug)]
pub struct InvalidRoomFormat;
impl RoomFormat { impl RoomFormat {
fn from(str: &str) -> Result<RoomFormat, &'static dyn Error> { fn from(str: &str) -> Result<RoomFormat, InvalidRoomFormat> {
match str { match str {
"0" => Ok(RoomFormat::Contiguous), "0" => Ok(RoomFormat::Contiguous),
"1" => Ok(RoomFormat::CommaSeparated), "1" => Ok(RoomFormat::CommaSeparated),
_ => panic!(format!("Invalid room format: {}", str)), _ => Err(InvalidRoomFormat),
} }
} }