Added try into for DanceRole
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user