rust: introduce alternative implementation of offset_of!
authorJunjie Mao <junjie.mao@hotmail.com>
Thu, 24 Oct 2024 10:25:15 +0000 (12:25 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 5 Nov 2024 13:18:16 +0000 (14:18 +0100)
commitf3518400882022ddcbe1148abf2165917a7b4640
tree0cc5f5dcd4b8a8b5d65d8caca317b76599d3f868
parent39c8faefb5e9bf1265cf754f43a17a4ac092d7a3
rust: introduce alternative implementation of offset_of!

offset_of! was stabilized in Rust 1.77.0.  Use an alternative implemenation
that was found on the Rust forums, and whose author agreed to license as
MIT for use in QEMU.

The alternative allows only one level of field access, but apart
from this can be used just by replacing core::mem::offset_of! with
qemu_api::offset_of!.

The actual implementation of offset_of! is done in a declarative macro,
but for simplicity and to avoid introducing an extra level of indentation,
the trigger is a procedural macro #[derive(offsets)].

The procedural macro is perhaps a bit overengineered, but it helps
introducing some idioms that will be useful in the future as well.

Signed-off-by: Junjie Mao <junjie.mao@hotmail.com>
Co-developed-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
13 files changed:
rust/Cargo.lock
rust/hw/char/pl011/src/device.rs
rust/qemu-api-macros/Cargo.toml
rust/qemu-api-macros/src/lib.rs
rust/qemu-api/Cargo.toml
rust/qemu-api/build.rs
rust/qemu-api/meson.build
rust/qemu-api/src/device_class.rs
rust/qemu-api/src/lib.rs
rust/qemu-api/src/offset_of.rs [new file with mode: 0644]
rust/qemu-api/src/vmstate.rs
rust/qemu-api/tests/tests.rs
subprojects/packagefiles/syn-2-rs/meson.build