Added try into for DanceRole

This commit is contained in:
Lukas Wölfer
2025-10-02 21:21:45 +02:00
parent d999f676ba
commit 95d13370c2

View File

@@ -21,6 +21,28 @@ impl DanceRole {
}
}
#[derive(Debug)]
pub struct ParseDanceRoleError;
impl std::fmt::Display for ParseDanceRoleError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "failed to parse DanceRole")
}
}
impl std::error::Error for ParseDanceRoleError {}
impl TryFrom<&str> for DanceRole {
type Error = ParseDanceRoleError;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value.to_lowercase().as_str() {
"leader" => Ok(DanceRole::Leader),
"follower" => Ok(DanceRole::Follower),
_ => Err(ParseDanceRoleError),
}
}
}
#[derive(serde::Deserialize, Debug, PartialEq, Eq)]
pub enum DanceRank {
Newcomer,