use serde_repr::Deserialize_repr;
use std::fmt::{self, Display, Formatter};
#[derive(Deserialize_repr, Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[repr(u8)]
pub enum Rank {
Unranked = 0,
CopperV = 1,
CopperIV = 2,
CopperIII = 3,
CopperII = 4,
CopperI = 5,
BronzeV = 6,
BronzeIV = 7,
BronzeIII = 8,
BronzeII = 9,
BronzeI = 10,
SilverV = 11,
SilverIV = 12,
SilverIII = 13,
SilverII = 14,
SilverI = 15,
GoldIII = 16,
GoldII = 17,
GoldI = 18,
PlatinumIII = 19,
PlatinumII = 20,
PlatinumI = 21,
Diamond = 22,
Champions = 23,
}
impl Rank {
pub fn is_unranked(self) -> bool {
Self::Unranked == self
}
pub fn is_copper(self) -> bool {
matches!(
self,
Self::CopperI | Self::CopperII | Self::CopperIII | Self::CopperIV | Self::CopperV
)
}
pub fn is_bronze(self) -> bool {
matches!(
self,
Self::BronzeI | Self::BronzeII | Self::BronzeIII | Self::BronzeIV | Self::BronzeV
)
}
pub fn is_silver(self) -> bool {
matches!(
self,
Self::SilverI | Self::SilverII | Self::SilverIII | Self::SilverIV | Self::SilverV
)
}
pub fn is_gold(self) -> bool {
matches!(self, Self::GoldI | Self::GoldII | Self::GoldIII)
}
pub fn is_platinum(self) -> bool {
matches!(self, Self::PlatinumI | Self::PlatinumII | Self::PlatinumIII)
}
pub fn is_diamond(self) -> bool {
Self::Diamond == self
}
pub fn is_champion(self) -> bool {
Self::Champions == self
}
}
impl Display for Rank {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Self::Unranked => write!(f, "Unranked"),
Self::CopperV => write!(f, "Copper V"),
Self::CopperIV => write!(f, "Copper IV"),
Self::CopperIII => write!(f, "Copper III"),
Self::CopperII => write!(f, "Copper II"),
Self::CopperI => write!(f, "Copper I"),
Self::BronzeV => write!(f, "Bronze V"),
Self::BronzeIV => write!(f, "Bronze IV"),
Self::BronzeIII => write!(f, "Bronze III"),
Self::BronzeII => write!(f, "Bronze II"),
Self::BronzeI => write!(f, "Bronze I"),
Self::SilverV => write!(f, "Silver V"),
Self::SilverIV => write!(f, "Silver IV"),
Self::SilverIII => write!(f, "Silver III"),
Self::SilverII => write!(f, "Silver II"),
Self::SilverI => write!(f, "Silver I"),
Self::GoldIII => write!(f, "Gold III"),
Self::GoldII => write!(f, "Gold II"),
Self::GoldI => write!(f, "Gold I"),
Self::PlatinumIII => write!(f, "Platinum III"),
Self::PlatinumII => write!(f, "Platinum II"),
Self::PlatinumI => write!(f, "Platinum I"),
Self::Diamond => write!(f, "Platinum"),
Self::Champions => write!(f, "Champions"),
}
}
}