Couple of clippy lints
Not 100% sure what the "must_use" is really for... so didn't "fix" them
This commit is contained in:
@@ -20,10 +20,8 @@ pub enum Colour {
|
||||
impl Suit {
|
||||
pub fn colour(&self) -> Colour {
|
||||
match *self {
|
||||
Suit::Heart => Colour::Red,
|
||||
Suit::Diamond => Colour::Red,
|
||||
Suit::Club => Colour::Black,
|
||||
Suit::Spade => Colour::Black,
|
||||
Suit::Heart | Suit::Diamond => Colour::Red,
|
||||
Suit::Club | Suit::Spade => Colour::Black,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +55,7 @@ pub enum Value {
|
||||
}
|
||||
|
||||
impl Value {
|
||||
pub fn indexed_values(&self) -> u8 {
|
||||
fn indexed_values(&self) -> u8 {
|
||||
// It might also make sense for Ace to be high... depends on context
|
||||
match self {
|
||||
Value::Ace => 1,
|
||||
@@ -119,7 +117,7 @@ pub enum StackingError {
|
||||
}
|
||||
|
||||
impl Card {
|
||||
pub fn can_be_placed_on_top(&self, top: Card) -> Result<(), StackingError> {
|
||||
pub fn can_be_placed_on_top(&self, top: &Card) -> Result<(), StackingError> {
|
||||
// Can't be the same Colour
|
||||
if self.suit.colour() == top.suit.colour() {
|
||||
return Err(StackingError::SameColour);
|
||||
@@ -146,8 +144,8 @@ impl Default for Deck {
|
||||
for value in Value::iter() {
|
||||
array.push(
|
||||
Card {
|
||||
suit: suit,
|
||||
value: value,
|
||||
suit,
|
||||
value,
|
||||
}
|
||||
);
|
||||
}
|
||||
@@ -173,22 +171,22 @@ mod tests {
|
||||
suit: Suit::Heart,
|
||||
value: Value::Six,
|
||||
};
|
||||
assert_eq!(testing_card.can_be_placed_on_top(bad_same_suit), Err(StackingError::SameColour));
|
||||
assert_eq!(testing_card.can_be_placed_on_top(&bad_same_suit), Err(StackingError::SameColour));
|
||||
let bad_same_colour = Card {
|
||||
suit: Suit::Diamond,
|
||||
value: Value::Six,
|
||||
};
|
||||
assert_eq!(testing_card.can_be_placed_on_top(bad_same_colour), Err(StackingError::SameColour));
|
||||
assert_eq!(testing_card.can_be_placed_on_top(&bad_same_colour), Err(StackingError::SameColour));
|
||||
let should_stack_card = Card {
|
||||
suit: Suit::Club,
|
||||
value: Value::Six,
|
||||
};
|
||||
assert_eq!(testing_card.can_be_placed_on_top(should_stack_card), Ok(()));
|
||||
assert_eq!(testing_card.can_be_placed_on_top(&should_stack_card), Ok(()));
|
||||
let value_too_high = Card {
|
||||
suit: Suit::Club,
|
||||
value: Value::Seven,
|
||||
};
|
||||
let not_adj_error = testing_card.can_be_placed_on_top(value_too_high);
|
||||
let not_adj_error = testing_card.can_be_placed_on_top(&value_too_high);
|
||||
if let Err(e) = not_adj_error {
|
||||
match e {
|
||||
StackingError::NotAdjacent(_, _) => assert!(true),
|
||||
|
||||
Reference in New Issue
Block a user