On 10/27/2025 2:23 PM, Zhao Liu wrote:
> On Sat, Oct 25, 2025 at 12:38:49PM +0000, chenmiao wrote:
>> Date: Sat, 25 Oct 2025 12:38:49 +0000
>> From: chenmiao <[email protected]>
>> Subject: [RFC 1/5] rust: hw: core: Add the BusState of rust version
>> X-Mailer: git-send-email 2.43.0
>>
>> A Rust version implementation has been designed for BusState,
>> which will be used for the subsequent I2CBus implementation.
>>
>> Signed-off-by: chenmiao <[email protected]>
>> ---
>>   rust/hw/core/meson.build |  1 +
>>   rust/hw/core/src/bus.rs  | 51 ++++++++++++++++++++++++++++++++++++++++
>>   rust/hw/core/src/lib.rs  |  3 +++
>>   3 files changed, 55 insertions(+)
>>   create mode 100644 rust/hw/core/src/bus.rs
> After a quick glance, I think this BusState is implemented quite well.
>
Thanks, hh. Paolo also provided many good suggestions regarding the
implementation of BusState.

>Only a few minor nits inline:
>
>...
>
>> +pub trait BusStateImpl: DeviceImpl + IsA<BusState> {}
>> +
>> +impl BusClass {
>> +    pub fn class_init<T: BusStateImpl>(self: &mut BusClass) {
>> +        self.parent_class.class_init::<T>();
>> +    }
>> +}
>> +
>> +pub trait BusStateMethods: ObjectDeref
>
>This can be named BusMethods - just like DeviceMethods did.
>

Thank you for pointing this out. I’ve noted the Rust In QEMU docs also include
relevant coding styles, and we’ll update the related naming conventions in the
next version.

>> +where
>> +    Self::Target: IsA<BusState>,
>> +{
>> +    fn bus_realize(&self) {
>
>"bus_" prefix is not needed:
>
>dummy_bus.realize() is clear and enough.
>
Ok, qbus_realize() is internally called by the C part during object
instantiation, so there is indeed no need for additional exporting.

>> +        assert!(bql::is_locked());
>
>It's better to add safety comment from beginning (// SAFETY: xxx).
>
Get~

>> +        unsafe {
>> +            bindings::qbus_realize(
>> +                self.upcast().as_mut_ptr(),
>> +                addr_of_mut!(util::bindings::error_fatal),
>> +            );
>> +        }
>> +    }
>> +}
>
>Regards,
>Zhao
>

Thanks,
Chao

Reply via email to