Add '# Safety' section to 'unsafe fn' doc

This commit is contained in:
Bruno BELANYI 2022-07-22 18:49:16 +02:00
parent 2eb7e4c8ef
commit 7dbe48ad23
6 changed files with 24 additions and 0 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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