aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 334eefd..63e53e2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -48,10 +48,16 @@ where
/// `address` is the address of the USB device which received the
/// report and `buffer` is the contents of the report itself.
pub fn new(callback: F) -> Self {
- Self {
- devices: [None; MAX_DEVICES],
- callback,
- }
+ let devices: [Option<Device>; MAX_DEVICES] = {
+ let mut devs: [MaybeUninit<Option<Device>>; MAX_DEVICES] =
+ unsafe { mem::MaybeUninit::uninit().assume_init() };
+ for dev in &mut devs[..] {
+ unsafe { ptr::write(dev.as_mut_ptr(), None) }
+ }
+ unsafe { mem::transmute(devs) }
+ };
+
+ Self { devices, callback }
}
}