mirror of https://github.com/Paoda/blue-gacha.git
feat: implement PartialOrd and Ord for Rarity
This commit is contained in:
parent
58080a9960
commit
c7b275ea22
23
src/gacha.rs
23
src/gacha.rs
|
@ -1,5 +1,6 @@
|
|||
use crate::student::Student;
|
||||
use serde_repr::{Deserialize_repr, Serialize_repr};
|
||||
use std::cmp::Ordering;
|
||||
#[derive(Debug, Clone, Copy, Serialize_repr, Deserialize_repr, PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
/// 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
|
||||
/// Representing single and 10-rolls
|
||||
///
|
||||
|
|
Loading…
Reference in New Issue