[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 44/49] rust: qom: move ClassInitImpl to the instance side
From: |
Paolo Bonzini |
Subject: |
[PULL 44/49] rust: qom: move ClassInitImpl to the instance side |
Date: |
Wed, 11 Dec 2024 17:27:14 +0100 |
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>
---
rust/hw/char/pl011/src/device.rs | 4 ++--
rust/qemu-api/src/definitions.rs | 8 ++++----
rust/qemu-api/tests/tests.rs | 2 +-
3 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index bcb146c24d6..2384d4bcb95 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -116,7 +116,7 @@ pub struct PL011Class {
_inner: [u8; 0],
}
-impl qemu_api::definitions::ClassInitImpl for PL011Class {
+impl qemu_api::definitions::ClassInitImpl for PL011State {
const CLASS_INIT: Option<unsafe extern "C" fn(klass: *mut ObjectClass,
data: *mut c_void)> =
Some(crate::device_class::pl011_class_init);
const CLASS_BASE_INIT: Option<
@@ -649,7 +649,7 @@ pub struct PL011LuminaryClass {
}
}
-impl qemu_api::definitions::ClassInitImpl for PL011LuminaryClass {
+impl qemu_api::definitions::ClassInitImpl for PL011Luminary {
const CLASS_INIT: Option<unsafe extern "C" fn(klass: *mut ObjectClass,
data: *mut c_void)> =
None;
const CLASS_BASE_INIT: Option<
diff --git a/rust/qemu-api/src/definitions.rs b/rust/qemu-api/src/definitions.rs
index 6ecfaf51b09..487712611f6 100644
--- a/rust/qemu-api/src/definitions.rs
+++ b/rust/qemu-api/src/definitions.rs
@@ -9,8 +9,8 @@
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(),
};
diff --git a/rust/qemu-api/tests/tests.rs b/rust/qemu-api/tests/tests.rs
index 7f9df348b00..fd0c979121c 100644
--- a/rust/qemu-api/tests/tests.rs
+++ b/rust/qemu-api/tests/tests.rs
@@ -59,7 +59,7 @@ impl ObjectImpl for DummyState {
const PARENT_TYPE_NAME: Option<&'static CStr> =
Some(device_class::TYPE_DEVICE);
}
- impl ClassInitImpl for DummyClass {
+ impl ClassInitImpl for DummyState {
const CLASS_INIT: Option<unsafe extern "C" fn(klass: *mut ObjectClass,
data: *mut c_void)> =
Some(dummy_class_init);
const CLASS_BASE_INIT: Option<
--
2.47.1
- [PULL 35/49] bql: check that the BQL is not dropped within marked sections, (continued)
- [PULL 35/49] bql: check that the BQL is not dropped within marked sections, Paolo Bonzini, 2024/12/11
- [PULL 36/49] rust: cell: add BQL-enforcing Cell variant, Paolo Bonzini, 2024/12/11
- [PULL 38/49] rust: define prelude, Paolo Bonzini, 2024/12/11
- [PULL 37/49] rust: cell: add BQL-enforcing RefCell variant, Paolo Bonzini, 2024/12/11
- [PULL 39/49] rust: add bindings for interrupt sources, Paolo Bonzini, 2024/12/11
- [PULL 40/49] rust: add a bit operation module, Paolo Bonzini, 2024/12/11
- [PULL 41/49] rust: qom: add default definitions for ObjectImpl, Paolo Bonzini, 2024/12/11
- [PULL 42/49] rust: qom: rename Class trait to ClassInitImpl, Paolo Bonzini, 2024/12/11
- [PULL 43/49] rust: qom: convert type_info! macro to an associated const, Paolo Bonzini, 2024/12/11
- [PULL 44/49] rust: qom: move ClassInitImpl to the instance side,
Paolo Bonzini <=
- [PULL 45/49] rust: qdev: move device_class_init! body to generic function, ClassInitImpl implementation to macro, Paolo Bonzini, 2024/12/11
- [PULL 46/49] rust: qdev: move bridge for realize and reset functions out of pl011, Paolo Bonzini, 2024/12/11
- [PULL 47/49] rust: qom: move bridge for TypeInfo functions out of pl011, Paolo Bonzini, 2024/12/11
- [PULL 48/49] rust: qom: split ObjectType from ObjectImpl trait, Paolo Bonzini, 2024/12/11
- [PULL 49/49] rust: qom: change the parent type to an associated type, Paolo Bonzini, 2024/12/11
- Re: [PULL 00/49] rust, QOM, kvm changes for 2024-12-11, Stefan Hajnoczi, 2024/12/12