Add '# Safety' section to 'unsafe fn' doc
This commit is contained in:
parent
2eb7e4c8ef
commit
7dbe48ad23
|
@ -26,6 +26,10 @@ impl CastleRights {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert from a castle rights index into a [CastleRights] type, no bounds checking.
|
/// 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)]
|
#[inline(always)]
|
||||||
pub unsafe fn from_index_unchecked(index: usize) -> Self {
|
pub unsafe fn from_index_unchecked(index: usize) -> Self {
|
||||||
std::mem::transmute(index as u8)
|
std::mem::transmute(index as u8)
|
||||||
|
|
|
@ -20,6 +20,10 @@ impl Color {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert from a piece index into a [Color] type, no bounds checking.
|
/// 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)]
|
#[inline(always)]
|
||||||
pub unsafe fn from_index_unchecked(index: usize) -> Self {
|
pub unsafe fn from_index_unchecked(index: usize) -> Self {
|
||||||
std::mem::transmute(index as u8)
|
std::mem::transmute(index as u8)
|
||||||
|
|
|
@ -43,6 +43,10 @@ impl File {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert from a file index into a [File] type, no bounds checking.
|
/// 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)]
|
#[inline(always)]
|
||||||
pub unsafe fn from_index_unchecked(index: usize) -> Self {
|
pub unsafe fn from_index_unchecked(index: usize) -> Self {
|
||||||
std::mem::transmute(index as u8)
|
std::mem::transmute(index as u8)
|
||||||
|
|
|
@ -36,6 +36,10 @@ impl Piece {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert from a piece index into a [Piece] type, no bounds checking.
|
/// 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)]
|
#[inline(always)]
|
||||||
pub unsafe fn from_index_unchecked(index: usize) -> Self {
|
pub unsafe fn from_index_unchecked(index: usize) -> Self {
|
||||||
std::mem::transmute(index as u8)
|
std::mem::transmute(index as u8)
|
||||||
|
|
|
@ -43,6 +43,10 @@ impl Rank {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert from a rank index into a [Rank] type, no bounds checking.
|
/// 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)]
|
#[inline(always)]
|
||||||
pub unsafe fn from_index_unchecked(index: usize) -> Self {
|
pub unsafe fn from_index_unchecked(index: usize) -> Self {
|
||||||
std::mem::transmute(index as u8)
|
std::mem::transmute(index as u8)
|
||||||
|
|
|
@ -59,6 +59,10 @@ impl Square {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convert from a square index into a [Square] type, no bounds checking.
|
/// 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)]
|
#[inline(always)]
|
||||||
pub unsafe fn from_index_unchecked(index: usize) -> Self {
|
pub unsafe fn from_index_unchecked(index: usize) -> Self {
|
||||||
std::mem::transmute(index as u8)
|
std::mem::transmute(index as u8)
|
||||||
|
|
Loading…
Reference in a new issue