diff --git a/src/game.rs b/src/game.rs index ea71f20..65c5c30 100644 --- a/src/game.rs +++ b/src/game.rs @@ -55,13 +55,19 @@ pub struct Version { pub minor: u8, } +#[derive(Debug)] +pub struct InvalidVersion; + impl Version { - fn from(str: &str) -> Version { + fn from(str: &str) -> Result { let parts: Vec<&str> = str.split(".").collect(); - assert_eq!(parts.len(), 2); - Version { - major: parts[0].parse().unwrap(), - minor: parts[1].parse().unwrap(), + if parts.len() == 2 { + Ok(Version { + major: parts[0].parse().unwrap(), + minor: parts[1].parse().unwrap(), + }) + } else { + Err (InvalidVersion) } } } @@ -142,7 +148,10 @@ impl Game { for segment in segments { if segment.starts_with("# BITSY VERSION") { let segment = segment.replace("# BITSY VERSION ", ""); - version = Some(Version::from(&segment)); + let segment = Version::from(&segment); + if segment.is_ok() { + version = Some(segment.unwrap()); + } } else if segment.starts_with("! ROOM_FORMAT") { let segment = segment.replace("! ROOM_FORMAT ", ""); room_format = Some(RoomFormat::from(&segment).unwrap());