[board] Create const arrays for Shape that return &'static to its enum cases
This commit is contained in:
parent
878d771d86
commit
750b16970f
3 changed files with 17 additions and 8 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
use crate::Square;
|
||||
use std::fmt;
|
||||
use std::slice::Iter;
|
||||
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum Color {
|
||||
|
@ -33,16 +34,24 @@ pub enum Shape {
|
|||
}
|
||||
|
||||
impl Shape {
|
||||
pub fn iter() -> impl Iterator<Item = Shape> {
|
||||
[
|
||||
pub fn iter() -> Iter<'static, Shape> {
|
||||
const ALL_SHAPES: [Shape; 6] = [
|
||||
Shape::Pawn,
|
||||
Shape::Knight,
|
||||
Shape::Bishop,
|
||||
Shape::Rook,
|
||||
Shape::Queen,
|
||||
Shape::King,
|
||||
]
|
||||
.into_iter()
|
||||
];
|
||||
|
||||
ALL_SHAPES.iter()
|
||||
}
|
||||
|
||||
pub fn promotable() -> Iter<'static, Shape> {
|
||||
const PROMOTABLE_SHAPES: [Shape; 4] =
|
||||
[Shape::Queen, Shape::Rook, Shape::Bishop, Shape::Knight];
|
||||
|
||||
PROMOTABLE_SHAPES.iter()
|
||||
}
|
||||
|
||||
fn _ascii_representation(&self) -> char {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue