aboutsummaryrefslogtreecommitdiff
path: root/rust/qemu-api/src/zeroable.rs
blob: 45ec95c9f703fbde6940c2e37b2d63e0144c65f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// SPDX-License-Identifier: GPL-2.0-or-later

/// Encapsulates the requirement that
/// `MaybeUninit::<Self>::zeroed().assume_init()` does not cause
/// undefined behavior.
///
/// # Safety
///
/// Do not add this trait to a type unless all-zeroes is
/// a valid value for the type.  In particular, remember that raw
/// pointers can be zero, but references and `NonNull<T>` cannot
/// unless wrapped with `Option<>`.
pub unsafe trait Zeroable: Default {
    /// SAFETY: If the trait was added to a type, then by definition
    /// this is safe.
    const ZERO: Self = unsafe { ::core::mem::MaybeUninit::<Self>::zeroed().assume_init() };
}

unsafe impl Zeroable for crate::bindings::Property__bindgen_ty_1 {}
unsafe impl Zeroable for crate::bindings::Property {}
unsafe impl Zeroable for crate::bindings::VMStateDescription {}
unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_1 {}
unsafe impl Zeroable for crate::bindings::MemoryRegionOps__bindgen_ty_2 {}