More parsing
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
use std::fmt;
|
||||
|
||||
#[derive(serde::Deserialize, Debug, PartialEq, Eq)]
|
||||
pub enum DanceRole {
|
||||
Leader,
|
||||
@@ -43,7 +45,7 @@ impl TryFrom<&str> for DanceRole {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize, Debug, PartialEq, Eq)]
|
||||
#[derive(serde::Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum DanceRank {
|
||||
Newcomer,
|
||||
Novice,
|
||||
@@ -68,6 +70,33 @@ impl DanceRank {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ParseDanceRankError;
|
||||
|
||||
impl fmt::Display for ParseDanceRankError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "failed to parse DanceRank")
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for ParseDanceRankError {}
|
||||
|
||||
impl std::str::FromStr for DanceRank {
|
||||
type Err = ParseDanceRankError;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s {
|
||||
"Newcomer" => Ok(Self::Newcomer),
|
||||
"Novice" => Ok(Self::Novice),
|
||||
"Intermediate" => Ok(Self::Intermediate),
|
||||
"Advanced" => Ok(Self::Advanced),
|
||||
"All-Stars" => Ok(Self::AllStars),
|
||||
"Champions" => Ok(Self::Champions),
|
||||
_ => Err(ParseDanceRankError),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CompState {
|
||||
pub rank: DanceRank,
|
||||
|
||||
Reference in New Issue
Block a user