qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 02/12] rust: add a utility module for compile-time type check


From: Paolo Bonzini
Subject: Re: [PATCH 02/12] rust: add a utility module for compile-time type checks
Date: Fri, 27 Dec 2024 05:26:32 +0100
User-agent: Mozilla Thunderbird

On 12/25/24 17:24, Zhao Liu wrote:
On Fri, Dec 20, 2024 at 03:29:44PM +0100, Paolo Bonzini wrote:
Date: Fri, 20 Dec 2024 15:29:44 +0100
From: Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH 02/12] rust: add a utility module for compile-time type
  checks
X-Mailer: git-send-email 2.47.1

It is relatively common in the low-level qemu_api code to assert that
a field of a struct has a specific type; for example, it can be used
to ensure that the fields match what the qemu_api and C code expects
for safety.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
  rust/qemu-api/meson.build       |  1 +
  rust/qemu-api/src/assertions.rs | 90 +++++++++++++++++++++++++++++++++
  rust/qemu-api/src/lib.rs        |  1 +
  3 files changed, 92 insertions(+)
  create mode 100644 rust/qemu-api/src/assertions.rs


Very useful! Previously I found qdev property macro lacks such type
check, but I falied to think of a good way to implement type_check in
Rust, and glad to see the correct approach! Besides qdev property, I
think vmstate also needs this.

Right, though for vmstate (and probably qdev properties too) it's probably better to go from types to C structs (PropertyInfo/VMStateField) and avoid having to do the assertions.

And I think we can make the examples as the unit tests.

Having doctests support in "make check" is on my list; I have started contributing a rust.doctest() function to Meson for that purpose. For now they are limited to what can be run through Cargo (i.e. you cannot use libqemuutil.a functions) but we'll see if the function is accepted.

Paolo

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>







reply via email to

[Prev in Thread] Current Thread [Next in Thread]