error for room type
This commit is contained in:
parent
96e9432f06
commit
d9764b6b42
13
src/game.rs
13
src/game.rs
|
@ -33,12 +33,15 @@ impl RoomFormat {
|
||||||
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
||||||
pub enum RoomType {Room, Set}
|
pub enum RoomType {Room, Set}
|
||||||
|
|
||||||
impl From<&str> for RoomType {
|
#[derive(Debug)]
|
||||||
fn from(string: &str) -> RoomType {
|
pub struct InvalidRoomType;
|
||||||
|
|
||||||
|
impl RoomType {
|
||||||
|
fn from(string: &str) -> Result<RoomType, InvalidRoomType> {
|
||||||
match string {
|
match string {
|
||||||
"ROOM" => RoomType::Room,
|
"ROOM" => Ok(RoomType::Room),
|
||||||
"SET" => RoomType::Set,
|
"SET" => Ok(RoomType::Set),
|
||||||
_ => panic!("Unrecognised room type"),
|
_ => Err(InvalidRoomType),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue