From 7dbe48ad230a7cc770ceb9576f8f949aea4ba9aa Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Fri, 22 Jul 2022 18:49:16 +0200 Subject: [PATCH] Add '# Safety' section to 'unsafe fn' doc --- 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 8ed8764..d727fd8 100644 --- a/src/board/castle_rights.rs +++ b/src/board/castle_rights.rs @@ -26,6 +26,10 @@ impl CastleRights { } /// Convert from a castle rights index into a [CastleRights] type, no bounds checking. + /// + /// # Safety + /// + /// Should only be called with values that can be output by [CastleRights::index()]. #[inline(always)] pub unsafe fn from_index_unchecked(index: usize) -> Self { std::mem::transmute(index as u8) diff --git a/src/board/color.rs b/src/board/color.rs index 09d017b..07024ee 100644 --- a/src/board/color.rs +++ b/src/board/color.rs @@ -20,6 +20,10 @@ impl Color { } /// Convert from a piece index into a [Color] type, no bounds checking. + /// + /// # Safety + /// + /// Should only be called with values that can be output by [Color::index()]. #[inline(always)] pub unsafe fn from_index_unchecked(index: usize) -> Self { std::mem::transmute(index as u8) diff --git a/src/board/file.rs b/src/board/file.rs index 55a138b..4c84f20 100644 --- a/src/board/file.rs +++ b/src/board/file.rs @@ -43,6 +43,10 @@ impl File { } /// Convert from a file index into a [File] type, no bounds checking. + /// + /// # Safety + /// + /// Should only be called with values that can be output by [File::index()]. #[inline(always)] pub unsafe fn from_index_unchecked(index: usize) -> Self { std::mem::transmute(index as u8) diff --git a/src/board/piece.rs b/src/board/piece.rs index 17ae913..58f989a 100644 --- a/src/board/piece.rs +++ b/src/board/piece.rs @@ -36,6 +36,10 @@ impl Piece { } /// Convert from a piece index into a [Piece] type, no bounds checking. + /// + /// # Safety + /// + /// Should only be called with values that can be output by [Piece::index()]. #[inline(always)] pub unsafe fn from_index_unchecked(index: usize) -> Self { std::mem::transmute(index as u8) diff --git a/src/board/rank.rs b/src/board/rank.rs index 70fad46..a0b04d3 100644 --- a/src/board/rank.rs +++ b/src/board/rank.rs @@ -43,6 +43,10 @@ impl Rank { } /// Convert from a rank index into a [Rank] type, no bounds checking. + /// + /// # Safety + /// + /// Should only be called with values that can be output by [Rank::index()]. #[inline(always)] pub unsafe fn from_index_unchecked(index: usize) -> Self { std::mem::transmute(index as u8) diff --git a/src/board/square.rs b/src/board/square.rs index 97d9bdc..9ffa824 100644 --- a/src/board/square.rs +++ b/src/board/square.rs @@ -59,6 +59,10 @@ impl Square { } /// Convert from a square index into a [Square] type, no bounds checking. + /// + /// # Safety + /// + /// Should only be called with values that can be output by [Square::index()]. #[inline(always)] pub unsafe fn from_index_unchecked(index: usize) -> Self { std::mem::transmute(index as u8)