Add 'Panics' section to 'from_index' methods

This commit is contained in:
Bruno BELANYI 2024-04-03 20:32:59 +01:00
parent 7d9c5edb99
commit 753f1590d1
6 changed files with 24 additions and 0 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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);

View file

@ -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