use std::io::{Result, Error, ErrorKind};
#[derive(Debug, PartialEq)]
pub enum Region {
USEast,
USWest,
SouthAmerica,
Europe,
Asia,
Australia,
MiddleEast,
Africa,
All, }
impl Region {
pub fn as_u8(&self) -> u8 {
match self {
Self::USEast => 0x00,
Self::USWest => 0x01,
Self::SouthAmerica => 0x02,
Self::Europe => 0x03,
Self::Asia => 0x04,
Self::Australia => 0x05,
Self::MiddleEast => 0x06,
Self::Africa => 0x07,
Self::All => 0xFF,
}
}
pub fn from_u8(code: u8) -> Result<Self> {
match code {
0x00 => Ok(Self::USEast),
0x01 => Ok(Self::USWest),
0x02 => Ok(Self::SouthAmerica),
0x03 => Ok(Self::Europe),
0x04 => Ok(Self::Asia),
0x05 => Ok(Self::Australia),
0x06 => Ok(Self::MiddleEast),
0x07 => Ok(Self::Africa),
0xFF => Ok(Self::All),
_ => Err(Error::new(ErrorKind::Other, "Invalid code")),
}
}
}