Is there a way to tell if Enum variants are directly sequential without assigning a value to each? For instance, I am trying to see if a poker hand is a straight and want to see if all five cards are in sequential value.
#[derive(PartialEq, PartialOrd, Eq, Hash, Copy, Clone, Debug)]
enum CardNumber {
Two,
Three,
Four,
Five,
Six,
Seven,
Eight,
Nine,
Ten,
Jack,
Queen,
King,
Ace,
}
fn is_sequential(card1, card2) {
card2 == card1 + 1 // pseudo code, function I'm looking for goes here.
}
use CardNumber::*;
let cards = [Ten, Jack, Queen, King, Ace];
let is_sequential: bool = cards
.windows(2)
.all(|(card1, card2)| is_sequential(card1, card2));
In order to compare whether variants are sequential, do I need to add a value to each variant, or is there another function that does this?