mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-27 12:23:53 -06:00
rust: qom: split ObjectType from ObjectImpl trait
Define a separate trait for fields that also applies to classes that are defined by C code. This makes it possible to add metadata to core classes, which has multiple uses: - it makes it possible to access the parent struct's TYPE_* for types that are defined in Rust code, and to avoid repeating it in every subclass - implementors of ObjectType will be allowed to implement the IsA<> trait and therefore to perform typesafe casts from one class to another. - in the future, an ObjectType could be created with Foo::new() in a type-safe manner, without having to pass a TYPE_* constant. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
1f9d52c938
commit
7bd8e3ef63
6 changed files with 58 additions and 26 deletions
|
@ -2,11 +2,17 @@
|
|||
// Author(s): Paolo Bonzini <pbonzini@redhat.com>
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
use std::ptr::addr_of;
|
||||
use std::{ffi::CStr, ptr::addr_of};
|
||||
|
||||
pub use bindings::{SysBusDevice, SysBusDeviceClass};
|
||||
|
||||
use crate::{bindings, cell::bql_locked, irq::InterruptSource};
|
||||
use crate::{bindings, cell::bql_locked, irq::InterruptSource, prelude::*};
|
||||
|
||||
unsafe impl ObjectType for SysBusDevice {
|
||||
type Class = SysBusDeviceClass;
|
||||
const TYPE_NAME: &'static CStr =
|
||||
unsafe { CStr::from_bytes_with_nul_unchecked(bindings::TYPE_SYS_BUS_DEVICE) };
|
||||
}
|
||||
|
||||
impl SysBusDevice {
|
||||
/// Return `self` cast to a mutable pointer, for use in calls to C code.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue