Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 787c16a9dc | |||
| 9599b7a50c | |||
| 0dfd51e25b |
+11
@@ -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"
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user