diff --git a/parser/src/keys/mod.rs b/parser/src/keys/mod.rs index 38c5ddd32..ce12f5f3b 100644 --- a/parser/src/keys/mod.rs +++ b/parser/src/keys/mod.rs @@ -11,36 +11,43 @@ mod windows; mod mappings; pub use mappings::*; +#[cfg(any(target_os = "unknown"))] #[derive(Clone, Copy)] pub enum Platform { Win, Linux, } -pub static OSCODE_MAPPING_VARIANT: Mutex = Mutex::new({ - if cfg!(target_os = "linux") { - Platform::Linux - } else if cfg!(target_os = "windows") { - Platform::Win - } else { - // use whatever value as a fallback - Platform::Linux - } -}); +#[cfg(any(target_os = "unknown"))] +pub static OSCODE_MAPPING_VARIANT: Mutex = Mutex::new(Platform::Linux); impl OsCode { pub fn as_u16(self) -> u16 { - match *OSCODE_MAPPING_VARIANT.lock() { + #[cfg(any(target_os = "unknown"))] + return match *OSCODE_MAPPING_VARIANT.lock() { Platform::Win => self.as_u16_windows(), Platform::Linux => self.as_u16_linux(), - } + }; + + #[cfg(any(target_os = "linux"))] + return self.as_u16_linux(); + + #[cfg(any(target_os = "windows"))] + return self.as_u16_windows(); } pub fn from_u16(code: u16) -> Option { - match *OSCODE_MAPPING_VARIANT.lock() { + #[cfg(any(target_os = "unknown"))] + return match *OSCODE_MAPPING_VARIANT.lock() { Platform::Win => OsCode::from_u16_windows(code), Platform::Linux => OsCode::from_u16_linux(code), - } + }; + + #[cfg(any(target_os = "linux"))] + return OsCode::from_u16_linux(code); + + #[cfg(any(target_os = "windows"))] + return OsCode::from_u16_windows(code); } }