Skip to main content

usehid_core/platform/
mod.rs

1//! Platform-specific HID backends
2
3use crate::error::Result;
4
5/// HID backend trait
6pub trait HidBackend: Send + Sync {
7    /// Send HID report
8    fn send_report(&self, report: &[u8]) -> Result<()>;
9    
10    /// Destroy the device
11    fn destroy(self: Box<Self>) -> Result<()>;
12}
13
14#[cfg(target_os = "macos")]
15mod macos;
16
17#[cfg(target_os = "linux")]
18mod linux;
19
20#[cfg(target_os = "windows")]
21mod windows;
22
23#[cfg(target_os = "macos")]
24pub use macos::*;
25
26#[cfg(target_os = "linux")]
27pub use linux::*;
28
29#[cfg(target_os = "windows")]
30pub use windows::*;
31
32// Fallback implementations for unsupported platforms
33#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
34mod fallback {
35    use super::*;
36    use crate::error::Error;
37    
38    pub fn create_mouse_backend(_name: &str) -> Result<Box<dyn HidBackend>> {
39        Err(Error::PlatformNotSupported("unsupported platform".into()))
40    }
41    
42    pub fn create_keyboard_backend(_name: &str) -> Result<Box<dyn HidBackend>> {
43        Err(Error::PlatformNotSupported("unsupported platform".into()))
44    }
45    
46    pub fn create_gamepad_backend(_name: &str) -> Result<Box<dyn HidBackend>> {
47        Err(Error::PlatformNotSupported("unsupported platform".into()))
48    }
49}
50
51#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
52pub use fallback::*;