error for room type

This commit is contained in:
Max Bradbury 2020-06-23 12:48:42 +01:00
parent 96e9432f06
commit d9764b6b42
1 changed files with 8 additions and 5 deletions

View File

@ -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<RoomType, InvalidRoomType> {
match string {
"ROOM" => RoomType::Room,
"SET" => RoomType::Set,
_ => panic!("Unrecognised room type"),
"ROOM" => Ok(RoomType::Room),
"SET" => Ok(RoomType::Set),
_ => Err(InvalidRoomType),
}
}
}