Skip to content

Commit 731f4d4

Browse files
committed
Conditionally compile disable_device_discovery
Skip all the relevant code where it is not supported, and it would result in a no-op. Currently, this means libusb + non-freebsd.
1 parent 7b513fd commit 731f4d4

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/lib.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,15 @@ pub type HidResult<T> = Result<T, HidError>;
124124
pub const MAX_REPORT_DESCRIPTOR_SIZE: usize = 4096;
125125

126126
enum InitState {
127-
Uninit { device_discovery: bool },
127+
Uninit {
128+
#[cfg(all(libusb, not(target_os = "freebsd")))]
129+
device_discovery: bool,
130+
},
128131
Init,
129132
}
130133

131134
static INIT_STATE: Mutex<InitState> = Mutex::new(InitState::Uninit {
135+
#[cfg(all(libusb, not(target_os = "freebsd")))]
132136
device_discovery: true,
133137
});
134138

@@ -151,6 +155,8 @@ impl HidApi {
151155
/// # Panics
152156
///
153157
/// Panics if an hidapi context has already been initialized.
158+
#[cfg(all(libusb, not(target_os = "freebsd")))]
159+
#[cfg_attr(docsrs, doc(cfg(not(target_os = "freebsd"))))]
154160
pub fn disable_device_discovery() {
155161
if let InitState::Uninit { device_discovery } = &mut *INIT_STATE.lock().unwrap() {
156162
*device_discovery = false;
@@ -166,8 +172,11 @@ impl HidApi {
166172
pub fn new() -> HidResult<Self> {
167173
let mut init_state = INIT_STATE.lock().expect("HidApi context initialization");
168174

169-
#[allow(unused_variables)]
170-
if let InitState::Uninit { device_discovery } = *init_state {
175+
if let InitState::Uninit {
176+
#[cfg(all(libusb, not(target_os = "freebsd")))]
177+
device_discovery,
178+
} = *init_state
179+
{
171180
#[cfg(all(libusb, not(target_os = "freebsd")))]
172181
if !device_discovery {
173182
// Do not scan for devices in libusb_init()

0 commit comments

Comments
 (0)