Something went wrong. Try again.
Something went wrong. Try again.
723 B · 38 lines
Rust
at libload
123456789101112131415161718192021222324252627282930313233343536373839use core::mem::transmute;
use wonderful::Control;
#[repr(C)]pub struct RawController { pub flags: *mut bool,}
pub struct ExternController { flags: &'static mut [bool; Control::variant_count()],}
impl ExternController { pub unsafe fn from_raw(raw: RawController) -> Self { unsafe { Self { flags: transmute(raw.flags.as_mut_unchecked()), } } }
pub fn state(&self) -> [bool; Control::variant_count()] { *self.flags }
pub fn set_state(&mut self, control: Control, state: bool) { self.flags[control as usize] = state; }
pub fn is_down(&self, control: Control) -> bool { self.flags[control as usize] }
pub fn is_up(&self, control: Control) -> bool { !self.flags[control as usize] }}