rust: vmstate: implement Zeroable for VMStateField

This shortens a bit the constants.  Do not bother using it
in the vmstate macros since most of them will go away soon.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2024-12-29 12:15:36 +01:00
parent 5b024b4e73
commit 2537f83098
2 changed files with 34 additions and 15 deletions

View file

@ -49,6 +49,37 @@ unsafe impl Zeroable for crate::bindings::Property {
};
}
// bindgen does not derive Default here
#[allow(clippy::derivable_impls)]
impl Default for crate::bindings::VMStateFlags {
fn default() -> Self {
Self(0)
}
}
unsafe impl Zeroable for crate::bindings::VMStateFlags {
const ZERO: Self = Self(0);
}
unsafe impl Zeroable for crate::bindings::VMStateField {
const ZERO: Self = Self {
name: ptr::null(),
err_hint: ptr::null(),
offset: 0,
size: 0,
start: 0,
num: 0,
num_offset: 0,
size_offset: 0,
info: ptr::null(),
flags: Zeroable::ZERO,
vmsd: ptr::null(),
version_id: 0,
struct_version_id: 0,
field_exists: None,
};
}
unsafe impl Zeroable for crate::bindings::VMStateDescription {
const ZERO: Self = Self {
name: ptr::null(),