From c7b275ea2273f0d38ce9917be786feced1ef422e Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Thu, 11 Feb 2021 20:21:08 -0600 Subject: [PATCH] feat: implement PartialOrd and Ord for Rarity --- src/gacha.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/gacha.rs b/src/gacha.rs index dd2b3f2..b84d236 100644 --- a/src/gacha.rs +++ b/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 { + 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 ///