Re: [PATCH 3/3] rust: add WMI abstractions
From: Kari Argillander
Date: Thu Jan 08 2026 - 15:48:33 EST
On Wed, 7 Jan 2026 at 22:56, Gladyshev Ilya <foxido@xxxxxxxxxx> wrote:
<snip>
> +impl DeviceId {
> + /// Constructs new DeviceId from GUID string.
> + pub const fn new(guid: &[u8; bindings::UUID_STRING_LEN as usize]) -> Self {
> + // SAFETY: FFI type is valid to be zero-initialized.
> + let mut inner: bindings::wmi_device_id = unsafe { MaybeUninit::zeroed().assume_init() };
> +
> + build_assert!(inner.guid_string.len() == bindings::UUID_STRING_LEN as usize + 1);
> +
> + // SAFETY: It's safe to copy UUID_STRING_LEN, because we validated lengths.
> + // Also we leave last byte zeroed, so guid_string is valid C string.
> + unsafe {
> + ::core::ptr::copy_nonoverlapping(
> + guid.as_ptr(),
> + &raw mut inner.guid_string[0],
> + bindings::UUID_STRING_LEN as usize,
> + );
> + }
Just use while here so no unsafe is needed at all. Then probably patch
1/3 is not needed.
> +
> + Self(inner)
> + }
> +}