Skip to content

Commit

Permalink
make OSCODE_MAPPING_VARIANT wasm-specific
Browse files Browse the repository at this point in the history
  • Loading branch information
rszyma committed Nov 16, 2023
1 parent dbb4163 commit 32fc783
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions parser/src/keys/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Platform> = 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<Platform> = 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<Self> {
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);
}
}

Expand Down

0 comments on commit 32fc783

Please sign in to comment.