feat: implement PartialOrd and Ord for Rarity

This commit is contained in:
Rekai Nyangadzayi Musuka 2021-02-11 20:21:08 -06:00
parent 58080a9960
commit c7b275ea22
1 changed files with 23 additions and 0 deletions

View File

@ -1,5 +1,6 @@
use crate::student::Student; use crate::student::Student;
use serde_repr::{Deserialize_repr, Serialize_repr}; use serde_repr::{Deserialize_repr, Serialize_repr};
use std::cmp::Ordering;
#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr, PartialEq, Eq)] #[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr, PartialEq, Eq)]
#[repr(u8)] #[repr(u8)]
/// The Available Rarities in Blue Archive's Gacha System /// The Available Rarities in Blue Archive's Gacha System
@ -25,6 +26,28 @@ impl Default for Rarity {
} }
} }
impl PartialOrd for Rarity {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(match (*self, other) {
(Rarity::One, Rarity::One) => Ordering::Equal,
(Rarity::One, Rarity::Two) => Ordering::Less,
(Rarity::One, Rarity::Three) => Ordering::Less,
(Rarity::Two, Rarity::One) => Ordering::Greater,
(Rarity::Two, Rarity::Two) => Ordering::Equal,
(Rarity::Two, Rarity::Three) => Ordering::Less,
(Rarity::Three, Rarity::One) => Ordering::Greater,
(Rarity::Three, Rarity::Two) => Ordering::Greater,
(Rarity::Three, Rarity::Three) => Ordering::Equal,
})
}
}
impl Ord for Rarity {
fn cmp(&self, other: &Self) -> Ordering {
self.partial_cmp(other).unwrap()
}
}
/// Recruitment is a trait that consists of two methods /// Recruitment is a trait that consists of two methods
/// Representing single and 10-rolls /// Representing single and 10-rolls
/// ///