91 lines
2.0 KiB
Rust
91 lines
2.0 KiB
Rust
#[derive(serde::Deserialize, Debug, PartialEq, Eq)]
|
|
pub enum DanceRole {
|
|
Leader,
|
|
Follower,
|
|
}
|
|
|
|
impl DanceRole {
|
|
pub const fn as_str(&self) -> &str {
|
|
match self {
|
|
Self::Leader => "Leader",
|
|
Self::Follower => "Follower",
|
|
}
|
|
}
|
|
|
|
#[allow(dead_code)]
|
|
pub const fn other(&self) -> Self {
|
|
match self {
|
|
Self::Leader => Self::Follower,
|
|
Self::Follower => Self::Leader,
|
|
}
|
|
}
|
|
}
|
|
|
|
#[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(Self::Leader),
|
|
"follower" => Ok(Self::Follower),
|
|
_ => Err(ParseDanceRoleError),
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(serde::Deserialize, Debug, PartialEq, Eq)]
|
|
pub enum DanceRank {
|
|
Newcomer,
|
|
Novice,
|
|
Intermediate,
|
|
#[serde(rename = "Advance")]
|
|
Advanced,
|
|
#[serde(rename = "All Star")]
|
|
AllStars,
|
|
Champions,
|
|
}
|
|
|
|
impl DanceRank {
|
|
pub const fn as_str(&self) -> &str {
|
|
match self {
|
|
Self::Newcomer => "Newcomer",
|
|
Self::Novice => "Novice",
|
|
Self::Intermediate => "Intermediate",
|
|
Self::Advanced => "Advanced",
|
|
Self::AllStars => "All-Stars",
|
|
Self::Champions => "Champions",
|
|
}
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct CompState {
|
|
pub rank: DanceRank,
|
|
pub points: u16,
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub struct DanceInfo {
|
|
pub firstname: String,
|
|
pub lastname: String,
|
|
pub dominant_role: DanceRole,
|
|
pub dominant_role_comp: CompState,
|
|
pub non_dominant_role_comp: Option<CompState>,
|
|
}
|
|
|
|
impl DanceInfo {
|
|
pub fn name(&self) -> String {
|
|
format!("{} {}", self.firstname, self.lastname)
|
|
}
|
|
}
|