card: rearrange
This commit is contained in:
35
src/card.rs
35
src/card.rs
@@ -257,6 +257,24 @@ mod traits_numerics {
|
|||||||
mod traits_ord {
|
mod traits_ord {
|
||||||
use super::*;
|
use super::*;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
|
|
||||||
|
impl Ord for PlayingCard {
|
||||||
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
|
self.abs().cmp(&other.abs())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Ord for Card {
|
||||||
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
|
match (self, other) {
|
||||||
|
(Self::PlayingCard(c1), Self::PlayingCard(c2)) => c1.cmp(c2),
|
||||||
|
(Self::Joker(_), Self::Joker(_)) => Ordering::Equal,
|
||||||
|
(Self::Joker(_), _) => Ordering::Less,
|
||||||
|
(_, Self::Joker(_)) => Ordering::Greater,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl PartialEq for PlayingCard {
|
impl PartialEq for PlayingCard {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.cmp(other) == Ordering::Equal
|
self.cmp(other) == Ordering::Equal
|
||||||
@@ -280,23 +298,6 @@ mod traits_ord {
|
|||||||
Some(self.cmp(other))
|
Some(self.cmp(other))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Ord for PlayingCard {
|
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
|
||||||
self.abs().cmp(&other.abs())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Ord for Card {
|
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
|
||||||
match (self, other) {
|
|
||||||
(Self::PlayingCard(c1), Self::PlayingCard(c2)) => c1.cmp(c2),
|
|
||||||
(Self::Joker(_), Self::Joker(_)) => Ordering::Equal,
|
|
||||||
(Self::Joker(_), _) => Ordering::Less,
|
|
||||||
(_, Self::Joker(_)) => Ordering::Greater,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mod traits_hash {
|
mod traits_hash {
|
||||||
|
|||||||
Reference in New Issue
Block a user