#[repr(u8)]
#[derive(Eq, PartialEq, Clone, Copy, Debug)]
pub enum GameResolution {
BlackWins = 1,
WhiteWins = 2,
Draw = 3,
Rematch = 4,
Aborted = 5,
}
impl GameResolution {
#[export_name = "GameResolution_from_u8_unchecked"]
pub unsafe extern "C" fn from_u8_unchecked(repr: u8) -> Self {
core::mem::transmute(repr)
}
}
impl_ord_for_fieldless_enum!(GameResolution);
impl_hash_for_fieldless_enum!(GameResolution);
#[repr(transparent)]
#[derive(Eq, PartialEq, Clone, Copy, Debug, Default)]
pub struct OptionGameResolution(u8);
impl From<Option<GameResolution>> for OptionGameResolution {
#[inline(always)]
fn from(arg: Option<GameResolution>) -> Self {
Self(match arg {
Some(result) => result as u8,
None => 0,
})
}
}
impl From<OptionGameResolution> for Option<GameResolution> {
#[inline(always)]
fn from(arg: OptionGameResolution) -> Self {
if arg.0 == 0 {
None
} else {
Some(unsafe { GameResolution::from_u8_unchecked(arg.0) })
}
}
}
impl_ord_for_single_field!(OptionGameResolution);
impl_hash_for_single_field!(OptionGameResolution);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn game_resolution_is_one_byte() {
assert_eq!(core::mem::size_of::<GameResolution>(), 1);
}
#[test]
fn option_game_resolution_default_is_compatible() {
assert_eq!(OptionGameResolution::default(), None.into());
}
}