From 753f1590d1cb3d509229f1628dc344b4522fc203 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 3 Apr 2024 20:32:59 +0100 Subject: [PATCH] Add 'Panics' section to 'from_index' methods --- src/board/castle_rights.rs | 4 ++++ src/board/color.rs | 4 ++++ src/board/file.rs | 4 ++++ src/board/piece.rs | 4 ++++ src/board/rank.rs | 4 ++++ src/board/square.rs | 4 ++++ 6 files changed, 24 insertions(+) diff --git a/src/board/castle_rights.rs b/src/board/castle_rights.rs index b34d952..5b06544 100644 --- a/src/board/castle_rights.rs +++ b/src/board/castle_rights.rs @@ -18,6 +18,10 @@ impl CastleRights { pub const NUM_VARIANTS: usize = 4; /// Convert from a castle rights index into a [CastleRights] type. + /// + /// # Panics + /// + /// Panics if the index is out of bounds. #[inline(always)] pub fn from_index(index: usize) -> Self { assert!(index < Self::NUM_VARIANTS); diff --git a/src/board/color.rs b/src/board/color.rs index 66b21b3..17ebcb5 100644 --- a/src/board/color.rs +++ b/src/board/color.rs @@ -19,6 +19,10 @@ impl Color { } /// Convert from a color index into a [Color] type. + /// + /// # Panics + /// + /// Panics if the index is out of bounds. #[inline(always)] pub fn from_index(index: usize) -> Self { assert!(index < Self::NUM_VARIANTS); diff --git a/src/board/file.rs b/src/board/file.rs index 1475e9a..5398660 100644 --- a/src/board/file.rs +++ b/src/board/file.rs @@ -35,6 +35,10 @@ impl File { } /// Convert from a file index into a [File] type. + /// + /// # Panics + /// + /// Panics if the index is out of bounds. #[inline(always)] pub fn from_index(index: usize) -> Self { assert!(index < Self::NUM_VARIANTS); diff --git a/src/board/piece.rs b/src/board/piece.rs index 58f989a..76d9df9 100644 --- a/src/board/piece.rs +++ b/src/board/piece.rs @@ -28,6 +28,10 @@ impl Piece { } /// Convert from a piece index into a [Piece] type. + /// + /// # Panics + /// + /// Panics if the index is out of bounds. #[inline(always)] pub fn from_index(index: usize) -> Self { assert!(index < Self::NUM_VARIANTS); diff --git a/src/board/rank.rs b/src/board/rank.rs index f448df5..f716bde 100644 --- a/src/board/rank.rs +++ b/src/board/rank.rs @@ -35,6 +35,10 @@ impl Rank { } /// Convert from a rank index into a [Rank] type. + /// + /// # Panics + /// + /// Panics if the index is out of bounds. #[inline(always)] pub fn from_index(index: usize) -> Self { assert!(index < Self::NUM_VARIANTS); diff --git a/src/board/square.rs b/src/board/square.rs index 958c3c9..afbd9bf 100644 --- a/src/board/square.rs +++ b/src/board/square.rs @@ -39,6 +39,10 @@ impl Square { ]; /// Construct a [Square] from a [File] and [Rank]. + /// + /// # Panics + /// + /// Panics if the index is out of bounds. #[inline(always)] pub fn new(file: File, rank: Rank) -> Self { // SAFETY: we know the value is in-bounds