mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-12-27 11:06:41 -05:00
rust: pin-init: improve documentation for Zeroable derive macros
Specify that both `MaybeZeroable` and `Zeroable` work on `union`s. Add a
doc example for a union. Also include an example with visibility on the
field.
Link: ab0985a0e0
Reviewed-by: Christian Schrefl <chrisi.schrefl@gmail.com>
Signed-off-by: Benno Lossin <benno.lossin@proton.me>
This commit is contained in:
@@ -395,9 +395,10 @@
|
||||
/// ```
|
||||
pub use ::pin_init_internal::pinned_drop;
|
||||
|
||||
/// Derives the [`Zeroable`] trait for the given struct.
|
||||
/// Derives the [`Zeroable`] trait for the given `struct` or `union`.
|
||||
///
|
||||
/// This can only be used for structs where every field implements the [`Zeroable`] trait.
|
||||
/// This can only be used for `struct`s/`union`s where every field implements the [`Zeroable`]
|
||||
/// trait.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@@ -406,14 +407,25 @@
|
||||
///
|
||||
/// #[derive(Zeroable)]
|
||||
/// pub struct DriverData {
|
||||
/// id: i64,
|
||||
/// pub(crate) id: i64,
|
||||
/// buf_ptr: *mut u8,
|
||||
/// len: usize,
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// ```
|
||||
/// use pin_init::Zeroable;
|
||||
///
|
||||
/// #[derive(Zeroable)]
|
||||
/// pub union SignCast {
|
||||
/// signed: i64,
|
||||
/// unsigned: u64,
|
||||
/// }
|
||||
/// ```
|
||||
pub use ::pin_init_internal::Zeroable;
|
||||
|
||||
/// Derives the [`Zeroable`] trait for the given struct if all fields implement [`Zeroable`].
|
||||
/// Derives the [`Zeroable`] trait for the given `struct` or `union` if all fields implement
|
||||
/// [`Zeroable`].
|
||||
///
|
||||
/// Contrary to the derive macro named [`macro@Zeroable`], this one silently fails when a field
|
||||
/// doesn't implement [`Zeroable`].
|
||||
@@ -426,7 +438,7 @@
|
||||
/// // implmements `Zeroable`
|
||||
/// #[derive(MaybeZeroable)]
|
||||
/// pub struct DriverData {
|
||||
/// id: i64,
|
||||
/// pub(crate) id: i64,
|
||||
/// buf_ptr: *mut u8,
|
||||
/// len: usize,
|
||||
/// }
|
||||
@@ -434,7 +446,7 @@
|
||||
/// // does not implmement `Zeroable`
|
||||
/// #[derive(MaybeZeroable)]
|
||||
/// pub struct DriverData2 {
|
||||
/// id: i64,
|
||||
/// pub(crate) id: i64,
|
||||
/// buf_ptr: *mut u8,
|
||||
/// len: usize,
|
||||
/// // this field doesn't implement `Zeroable`
|
||||
|
||||
Reference in New Issue
Block a user