lkml.org 
[lkml]   [2023]   [Jul]   [14]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
SubjectRe: [PATCH] rust: init: Implement Zeroable::zeroed()
From
Asahi Lina <lina@asahilina.net> writes:
> +pub unsafe trait Zeroable: core::marker::Sized {
> + /// Create a new zeroed T.
> + ///
> + /// Directly returns a zeroed T, analogous to Default::default().
> + fn zeroed() -> Self {
> + unsafe { core::mem::zeroed() }
> + }
> +}

I don't think this trait needs to require `Sized`. How about the
following alternate implementation?

pub unsafe trait Zeroable {
/// Create a new zeroed T.
///
/// Directly returns a zeroed T, analogous to Default::default().
fn zeroed() -> Self
where
Self: core::marker::Sized,
{
unsafe { core::mem::zeroed() }
}
}

Then types like [T] can also implement Zeroable when T does.

If you make the above change, then you may add my
Reviewed-by: Alice Ryhl <aliceryhl@google.com>

Alice

\
 
 \ /
  Last update: 2023-07-16 20:48    [W:0.035 / U:1.224 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site