}
impl DeviceImpl for PL011State {
- fn vmsd() -> Option<VMStateDescription<Self>> {
- Some(VMSTATE_PL011)
- }
+ const VMSTATE: Option<VMStateDescription<Self>> = Some(VMSTATE_PL011);
const REALIZE: Option<fn(&Self) -> qemu_api::Result<()>> = Some(Self::realize);
}
// SAFETY: HPET_PROPERTIES is a valid Property array constructed with the
// qemu_api::declare_properties macro.
unsafe impl qemu_api::qdev::DevicePropertiesImpl for HPETState {
- fn properties() -> &'static [Property] {
- &HPET_PROPERTIES
- }
+ const PROPERTIES: &'static [Property] = &HPET_PROPERTIES;
}
impl DeviceImpl for HPETState {
- fn vmsd() -> Option<VMStateDescription<Self>> {
- Some(VMSTATE_HPET)
- }
-
+ const VMSTATE: Option<VMStateDescription<Self>> = Some(VMSTATE_HPET);
const REALIZE: Option<fn(&Self) -> qemu_api::Result<()>> = Some(Self::realize);
}
Ok(quote_spanned! {input.span() =>
unsafe impl ::qemu_api::qdev::DevicePropertiesImpl for #name {
- fn properties() -> &'static [::qemu_api::bindings::Property] {
- static PROPERTIES: &[::qemu_api::bindings::Property] = &[#(#properties_expanded),*];
-
- PROPERTIES
- }
+ const PROPERTIES: &'static [::qemu_api::bindings::Property] = &[
+ #(#properties_expanded),*
+ ];
}
})
}
},
quote! {
unsafe impl ::qemu_api::qdev::DevicePropertiesImpl for DummyState {
- fn properties() -> &'static [::qemu_api::bindings::Property] {
- static PROPERTIES: &[::qemu_api::bindings::Property] =
- &[::qemu_api::bindings::Property {
- name: ::std::ffi::CStr::as_ptr(c"migrate_clock"),
- info: <bool as ::qemu_api::qdev::QDevProp>::VALUE,
- offset: ::core::mem::offset_of!(DummyState, migrate_clock) as isize,
- set_default: true,
- defval: ::qemu_api::bindings::Property__bindgen_ty_1 { u: true as u64 },
- ..::qemu_api::zeroable::Zeroable::ZERO
- }];
- PROPERTIES
- }
+ const PROPERTIES: &'static [::qemu_api::bindings::Property] = &[
+ ::qemu_api::bindings::Property {
+ name: ::std::ffi::CStr::as_ptr(c"migrate_clock"),
+ info: <bool as ::qemu_api::qdev::QDevProp>::VALUE,
+ offset: ::core::mem::offset_of!(DummyState, migrate_clock) as isize,
+ set_default: true,
+ defval: ::qemu_api::bindings::Property__bindgen_ty_1 { u: true as u64 },
+ ..::qemu_api::zeroable::Zeroable::ZERO
+ }
+ ];
}
}
);
},
quote! {
unsafe impl ::qemu_api::qdev::DevicePropertiesImpl for DummyState {
- fn properties() -> &'static [::qemu_api::bindings::Property] {
- static PROPERTIES: &[::qemu_api::bindings::Property] =
- &[::qemu_api::bindings::Property {
- name: ::std::ffi::CStr::as_ptr(c"migrate-clk"),
- info: <bool as ::qemu_api::qdev::QDevProp>::VALUE,
- offset: ::core::mem::offset_of!(DummyState, migrate_clock) as isize,
- set_default: true,
- defval: ::qemu_api::bindings::Property__bindgen_ty_1 { u: true as u64 },
- ..::qemu_api::zeroable::Zeroable::ZERO
- }];
- PROPERTIES
- }
+ const PROPERTIES: &'static [::qemu_api::bindings::Property] = &[
+ ::qemu_api::bindings::Property {
+ name: ::std::ffi::CStr::as_ptr(c"migrate-clk"),
+ info: <bool as ::qemu_api::qdev::QDevProp>::VALUE,
+ offset: ::core::mem::offset_of!(DummyState, migrate_clock) as isize,
+ set_default: true,
+ defval: ::qemu_api::bindings::Property__bindgen_ty_1 { u: true as u64 },
+ ..::qemu_api::zeroable::Zeroable::ZERO
+ }
+ ];
}
}
);
/// Caller is responsible for the validity of properties array.
pub unsafe trait DevicePropertiesImpl {
/// An array providing the properties that the user can set on the
- /// device. Not a `const` because referencing statics in constants
- /// is unstable until Rust 1.83.0.
- fn properties() -> &'static [Property] {
- &[]
- }
+ /// device.
+ const PROPERTIES: &'static [Property] = &[];
}
/// Trait providing the contents of [`DeviceClass`].
/// A `VMStateDescription` providing the migration format for the device
/// Not a `const` because referencing statics in constants is unstable
/// until Rust 1.83.0.
- fn vmsd() -> Option<VMStateDescription<Self>> {
- None
- }
+ const VMSTATE: Option<VMStateDescription<Self>> = None;
}
/// # Safety
if <T as DeviceImpl>::REALIZE.is_some() {
self.realize = Some(rust_realize_fn::<T>);
}
- if let Some(vmsd) = <T as DeviceImpl>::vmsd() {
- // Give a 'static lifetime to the return value of vmsd().
- // Temporary until vmsd() can be changed into a const.
- self.vmsd = Box::leak(Box::new(vmsd.get()));
+ if let Some(ref vmsd) = <T as DeviceImpl>::VMSTATE {
+ self.vmsd = vmsd.as_ref();
}
- let prop = <T as DevicePropertiesImpl>::properties();
+ let prop = <T as DevicePropertiesImpl>::PROPERTIES;
if !prop.is_empty() {
unsafe {
bindings::device_class_set_props_n(self, prop.as_ptr(), prop.len());
impl ResettablePhasesImpl for DummyState {}
impl DeviceImpl for DummyState {
- fn vmsd() -> Option<VMStateDescription<Self>> {
- Some(VMSTATE)
- }
+ const VMSTATE: Option<VMStateDescription<Self>> = Some(VMSTATE);
}
#[repr(C)]