rust/qdev: Support property info for more common types
Add a helper macro to implement QDevProp trait for u8/u16/u32/usize/i32 /i64. Signed-off-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Link: https://lore.kernel.org/r/20250920160520.3699591-8-zhao1.liu@intel.com
This commit is contained in:
parent
bed2a37b20
commit
b4221e88a9
1 changed files with 16 additions and 12 deletions
|
|
@ -134,20 +134,24 @@ pub unsafe trait QDevProp {
|
|||
const VALUE: *const bindings::PropertyInfo;
|
||||
}
|
||||
|
||||
/// Use [`bindings::qdev_prop_bool`] for `bool`.
|
||||
unsafe impl QDevProp for bool {
|
||||
const VALUE: *const bindings::PropertyInfo = addr_of!(bindings::qdev_prop_bool);
|
||||
macro_rules! impl_qdev_prop {
|
||||
($type:ty,$info:ident) => {
|
||||
unsafe impl $crate::qdev::QDevProp for $type {
|
||||
const VALUE: *const $crate::bindings::PropertyInfo =
|
||||
addr_of!($crate::bindings::$info);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// Use [`bindings::qdev_prop_uint64`] for `u64`.
|
||||
unsafe impl QDevProp for u64 {
|
||||
const VALUE: *const bindings::PropertyInfo = addr_of!(bindings::qdev_prop_uint64);
|
||||
}
|
||||
|
||||
/// Use [`bindings::qdev_prop_chr`] for [`chardev::CharBackend`].
|
||||
unsafe impl QDevProp for chardev::CharBackend {
|
||||
const VALUE: *const bindings::PropertyInfo = addr_of!(bindings::qdev_prop_chr);
|
||||
}
|
||||
impl_qdev_prop!(bool, qdev_prop_bool);
|
||||
impl_qdev_prop!(u8, qdev_prop_uint8);
|
||||
impl_qdev_prop!(u16, qdev_prop_uint16);
|
||||
impl_qdev_prop!(u32, qdev_prop_uint32);
|
||||
impl_qdev_prop!(u64, qdev_prop_uint64);
|
||||
impl_qdev_prop!(usize, qdev_prop_usize);
|
||||
impl_qdev_prop!(i32, qdev_prop_int32);
|
||||
impl_qdev_prop!(i64, qdev_prop_int64);
|
||||
impl_qdev_prop!(chardev::CharBackend, qdev_prop_chr);
|
||||
|
||||
/// Trait to define device properties.
|
||||
///
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue