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 <pbonz...@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 <pbonz...@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. And I think we can make the examples as the unit tests. Reviewed-by: Zhao Liu <zhao1....@intel.com>