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 {
|
impl Suit {
|
||||||
pub fn colour(&self) -> Colour {
|
pub fn colour(&self) -> Colour {
|
||||||
match *self {
|
match *self {
|
||||||
Suit::Heart => Colour::Red,
|
Suit::Heart | Suit::Diamond => Colour::Red,
|
||||||
Suit::Diamond => Colour::Red,
|
Suit::Club | Suit::Spade => Colour::Black,
|
||||||
Suit::Club => Colour::Black,
|
|
||||||
Suit::Spade => Colour::Black,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,7 +55,7 @@ pub enum Value {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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
|
// It might also make sense for Ace to be high... depends on context
|
||||||
match self {
|
match self {
|
||||||
Value::Ace => 1,
|
Value::Ace => 1,
|
||||||
@@ -119,7 +117,7 @@ pub enum StackingError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Card {
|
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
|
// Can't be the same Colour
|
||||||
if self.suit.colour() == top.suit.colour() {
|
if self.suit.colour() == top.suit.colour() {
|
||||||
return Err(StackingError::SameColour);
|
return Err(StackingError::SameColour);
|
||||||
@@ -146,8 +144,8 @@ impl Default for Deck {
|
|||||||
for value in Value::iter() {
|
for value in Value::iter() {
|
||||||
array.push(
|
array.push(
|
||||||
Card {
|
Card {
|
||||||
suit: suit,
|
suit,
|
||||||
value: value,
|
value,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -173,22 +171,22 @@ mod tests {
|
|||||||
suit: Suit::Heart,
|
suit: Suit::Heart,
|
||||||
value: Value::Six,
|
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 {
|
let bad_same_colour = Card {
|
||||||
suit: Suit::Diamond,
|
suit: Suit::Diamond,
|
||||||
value: Value::Six,
|
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 {
|
let should_stack_card = Card {
|
||||||
suit: Suit::Club,
|
suit: Suit::Club,
|
||||||
value: Value::Six,
|
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 {
|
let value_too_high = Card {
|
||||||
suit: Suit::Club,
|
suit: Suit::Club,
|
||||||
value: Value::Seven,
|
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 {
|
if let Err(e) = not_adj_error {
|
||||||
match e {
|
match e {
|
||||||
StackingError::NotAdjacent(_, _) => assert!(true),
|
StackingError::NotAdjacent(_, _) => assert!(true),
|
||||||
|
|||||||
Reference in New Issue
Block a user