From 892c1124337d0624be623f8daa1ea944f178adde Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Fri, 3 Apr 2026 23:56:22 +0100 Subject: [PATCH] helper: ordered now takes a fixed sized array of type T I wanted to abstract ordered to any size instead of just binary tuples - but tuples have a strange issue where you can't be generic about them past like a limit of 12. With this setup, ordered takes ownership of some fixed array, sorts it, then returns it back. modes:pair and modes:single have been refactored to utilise this new form of ordered - it's basically the exact same in these cases. --- src/helper.rs | 7 +++---- src/modes/pair.rs | 4 ++-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/helper.rs b/src/helper.rs index 485f6fa..2c91f75 100644 --- a/src/helper.rs +++ b/src/helper.rs @@ -1,5 +1,4 @@ -use std::cmp::{max, min}; - -pub fn ordered(x: T, y: T) -> (T, T) { - (min(x, y), max(x, y)) +pub fn ordered(mut xs: [T; N]) -> [T; N] { + xs.sort(); + xs } diff --git a/src/modes/pair.rs b/src/modes/pair.rs index 9bda445..c221838 100644 --- a/src/modes/pair.rs +++ b/src/modes/pair.rs @@ -15,7 +15,7 @@ impl Pair { fn new(c1: Card, c2: Card) -> Option { // Order the cards. This means if xor(c1 is joker, c2 is joker) c1 will // be that joker. - let (c1, c2) = ordered(c1, c2); + let [c1, c2] = ordered([c1, c2]); match (c1, c2) { // Can't be a pair if you got two jokers homie. @@ -192,7 +192,7 @@ mod tests { }) .for_each(|(c1, c2, pair)| { // TEST: Pairs always sort their cards in strength. - let (b1, b2) = ordered(c1, c2); + let [b1, b2] = ordered([c1, c2]); assert_eq!(pair.0, b1, "Expected {} to be {b1}", pair.0); assert_eq!(pair.1, b2, "Expected {} to be {b2}", pair.1); });