aboutsummaryrefslogtreecommitdiff
path: root/rust/qemu-api/src
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2024-10-28 14:42:23 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2024-12-10 18:49:26 +0100
commitc6c4f3e0d90990c642523c087482eac3f42566c1 (patch)
tree3e0b247f9cd6f5977a56d596626d048d38f9f461 /rust/qemu-api/src
parent3701fb22dfd438993e76e158beb97683359d1dd9 (diff)
downloadqemu-c6c4f3e0d90990c642523c087482eac3f42566c1.zip
qemu-c6c4f3e0d90990c642523c087482eac3f42566c1.tar.gz
qemu-c6c4f3e0d90990c642523c087482eac3f42566c1.tar.bz2
rust: qom: move ClassInitImpl to the instance side
Put all traits on the instance struct, which makes it possible to reuse class structs if no new virtual methods or class fields are added. This is almost always the case for devices (because they are leaf classes), which is the primary use case for Rust. This is also simpler: soon we will find the implemented methods without macros, and this removes the need to go from the class struct to the instance struct to find the implementation of the *Impl traits. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'rust/qemu-api/src')
-rw-r--r--rust/qemu-api/src/definitions.rs8
1 files changed, 4 insertions, 4 deletions
diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs
index 6ecfaf5..4877126 100644
--- a/rust/qemu-api/src/definitions.rs
+++ b/rust/qemu-api/src/definitions.rs
@@ -9,8 +9,8 @@ use std::{ffi::CStr, os::raw::c_void};
use crate::bindings::{Object, ObjectClass, TypeInfo};
/// Trait a type must implement to be registered with QEMU.
-pub trait ObjectImpl: Sized {
- type Class: ClassInitImpl;
+pub trait ObjectImpl: ClassInitImpl + Sized {
+ type Class;
const TYPE_NAME: &'static CStr;
const PARENT_TYPE_NAME: Option<&'static CStr>;
const ABSTRACT: bool = false;
@@ -32,8 +32,8 @@ pub trait ObjectImpl: Sized {
instance_finalize: Self::INSTANCE_FINALIZE,
abstract_: Self::ABSTRACT,
class_size: core::mem::size_of::<Self::Class>(),
- class_init: <Self::Class as ClassInitImpl>::CLASS_INIT,
- class_base_init: <Self::Class as ClassInitImpl>::CLASS_BASE_INIT,
+ class_init: <Self as ClassInitImpl>::CLASS_INIT,
+ class_base_init: <Self as ClassInitImpl>::CLASS_BASE_INIT,
class_data: core::ptr::null_mut(),
interfaces: core::ptr::null_mut(),
};