aboutsummaryrefslogtreecommitdiff
path: root/rust/qemu-api/src
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2024-11-24 18:51:34 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2024-12-11 15:57:19 +0100
commit166e8a1fd15bfa527b25fc15ca315e572c0556d2 (patch)
treed72f812798ea3ded3bda9130b0469175f49d3381 /rust/qemu-api/src
parent7bd8e3ef63330e870cf4644d21c285cce35c703d (diff)
downloadqemu-166e8a1fd15bfa527b25fc15ca315e572c0556d2.zip
qemu-166e8a1fd15bfa527b25fc15ca315e572c0556d2.tar.gz
qemu-166e8a1fd15bfa527b25fc15ca315e572c0556d2.tar.bz2
rust: qom: change the parent type to an associated type
Avoid duplicated code to retrieve the QOM type strings from the Rust type. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'rust/qemu-api/src')
-rw-r--r--rust/qemu-api/src/definitions.rs12
1 files changed, 4 insertions, 8 deletions
diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs
index b98a692..df91a2e 100644
--- a/rust/qemu-api/src/definitions.rs
+++ b/rust/qemu-api/src/definitions.rs
@@ -45,10 +45,10 @@ unsafe extern "C" fn rust_instance_post_init<T: ObjectImpl>(obj: *mut Object) {
/// - the struct must be `#[repr(C)]`;
///
/// - the first field of the struct must be of the instance struct corresponding
-/// to the superclass, as declared in `ObjectImpl::PARENT_TYPE_NAME`
+/// to the superclass, which is `ObjectImpl::ParentType`
///
/// - likewise, the first field of the `Class` must be of the class struct
-/// corresponding to the superclass
+/// corresponding to the superclass, which is `ObjectImpl::ParentType::Class`.
pub unsafe trait ObjectType: Sized {
/// The QOM class object corresponding to this struct. Not used yet.
type Class;
@@ -62,7 +62,7 @@ pub unsafe trait ObjectType: Sized {
pub trait ObjectImpl: ObjectType + ClassInitImpl {
/// The parent of the type. This should match the first field of
/// the struct that implements `ObjectImpl`:
- const PARENT_TYPE_NAME: Option<&'static CStr>;
+ type ParentType: ObjectType;
/// Whether the object can be instantiated
const ABSTRACT: bool = false;
@@ -82,11 +82,7 @@ pub trait ObjectImpl: ObjectType + ClassInitImpl {
const TYPE_INFO: TypeInfo = TypeInfo {
name: Self::TYPE_NAME.as_ptr(),
- parent: if let Some(pname) = Self::PARENT_TYPE_NAME {
- pname.as_ptr()
- } else {
- core::ptr::null_mut()
- },
+ parent: Self::ParentType::TYPE_NAME.as_ptr(),
instance_size: core::mem::size_of::<Self>(),
instance_align: core::mem::align_of::<Self>(),
instance_init: match Self::INSTANCE_INIT {