Re: [PATCH 1/2] rust: usb: add basic USB abstractions
From: Benno Lossin
Date: Mon Aug 25 2025 - 16:49:53 EST
On Mon Aug 25, 2025 at 8:18 PM CEST, Daniel Almeida wrote:
> +impl DeviceId {
> + /// Equivalent to C's `USB_DEVICE` macro.
> + pub const fn from_id(vendor: u16, product: u16) -> Self {
> + Self(bindings::usb_device_id {
> + match_flags: bindings::USB_DEVICE_ID_MATCH_DEVICE as u16,
> + idVendor: vendor,
> + idProduct: product,
> + // SAFETY: It is safe to use all zeroes for the other fields of `usb_device_id`.
> + ..unsafe { MaybeUninit::zeroed().assume_init() }
You can avoid this usage of `unsafe` with this patch series:
https://lore.kernel.org/all/20250814093046.2071971-1-lossin@xxxxxxxxxx
I'd like to avoid introducing any new one of these.
---
Cheers,
Benno
> + })
> + }