update WeatherType to use strum internally

This commit is contained in:
Zoey 2024-04-24 23:32:19 -07:00
parent 76b8339048
commit b749eb838b
No known key found for this signature in database
GPG key ID: 8611B896D1AAFAF2

View file

@ -163,7 +163,8 @@ pub struct BlockUpdate {
}
/// weather types for a level
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, Serialize, Deserialize, strum::EnumString, strum::IntoStaticStr)]
#[strum(ascii_case_insensitive)]
pub enum WeatherType {
Sunny,
Raining,
@ -195,16 +196,3 @@ impl From<u8> for WeatherType {
}
}
}
impl TryFrom<&str> for WeatherType {
type Error = ();
fn try_from(value: &str) -> Result<Self, Self::Error> {
Ok(match value {
"sunny" => Self::Sunny,
"raining" => Self::Raining,
"snowing" => Self::Snowing,
_ => return Err(()),
})
}
}