3 Commits

Author SHA1 Message Date
Quaternions 787c16a9dc add wacky lints 2026-05-18 11:11:56 -07:00
Quaternions 9599b7a50c const 2026-05-18 11:11:56 -07:00
Quaternions 0dfd51e25b cannot support more than 4 decks with range packing because 255 < 52 * 5 2026-05-18 11:06:47 -07:00
2 changed files with 16 additions and 6 deletions
+11
View File
@@ -5,3 +5,14 @@ members = [
"klondike-cli", "klondike-cli",
] ]
resolver = "3" resolver = "3"
[workspace.lints.rust]
# unsafe_code = "forbid"
# missing_docs = "warn"
# missing_debug_implementations = "warn"
single_use_lifetimes = "warn"
trivial_casts = "warn"
unused_lifetimes = "warn"
unused_qualifications = "warn"
# variant_size_differences = "warn"
unexpected_cfgs = "warn"
+5 -6
View File
@@ -47,11 +47,11 @@ pub enum Suit {
impl Suit { impl Suit {
pub const SUITS: [Self; 4] = [Self::Spades, Self::Hearts, Self::Clubs, Self::Diamonds]; pub const SUITS: [Self; 4] = [Self::Spades, Self::Hearts, Self::Clubs, Self::Diamonds];
/// Is the suit red. /// Is the suit red.
pub fn is_red(self) -> bool { pub const fn is_red(self) -> bool {
self as u8 & 0b01 != 0 self as u8 & 0b01 != 0
} }
/// Is the suit shape spikey. (Bouba/kiki) /// Is the suit shape spikey. (Bouba/kiki)
pub fn is_kiki(self) -> bool { pub const fn is_kiki(self) -> bool {
self as u8 & 0b10 != 0 self as u8 & 0b10 != 0
} }
} }
@@ -124,7 +124,6 @@ impl Rank {
/// 2 bits for deck ID /// 2 bits for deck ID
/// 2 bits for suit ID /// 2 bits for suit ID
/// 4 bits for card Value /// 4 bits for card Value
/// TODO: better encoding for slightly more decks
#[derive(Clone, Debug, Eq, Hash, PartialEq)] #[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct Card(core::num::NonZeroU8); pub struct Card(core::num::NonZeroU8);
impl Card { impl Card {
@@ -216,13 +215,13 @@ pub struct Pile<const DN: usize, const UP: usize> {
face_up: Stack<UP>, face_up: Stack<UP>,
} }
impl<const DN: usize, const UP: usize> Pile<DN, UP> { impl<const DN: usize, const UP: usize> Pile<DN, UP> {
pub fn new() -> Self { pub const fn new() -> Self {
Self { Self {
face_down: Stack::new(), face_down: Stack::new(),
face_up: Stack::new(), face_up: Stack::new(),
} }
} }
pub fn new_face_down(stack: Stack<DN>) -> Self { pub const fn new_face_down(stack: Stack<DN>) -> Self {
Self { Self {
face_down: stack, face_down: stack,
face_up: Stack::new(), face_up: Stack::new(),
@@ -277,7 +276,7 @@ impl<const CAP: usize> Pile<CAP, CAP> {
self.swap_up_down(); self.swap_up_down();
self.face_down.reverse(); self.face_down.reverse();
} }
pub fn swap_up_down(&mut self) { pub const fn swap_up_down(&mut self) {
core::mem::swap(&mut self.face_up, &mut self.face_down); core::mem::swap(&mut self.face_up, &mut self.face_down);
} }
} }