summary refs log tree commit diff stats
path: root/rust/qemu-api/src/lib.rs
diff options
context:
space:
mode:
authorJunjie Mao <junjie.mao@hotmail.com>2024-10-24 12:25:15 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2024-11-05 14:18:16 +0100
commitf3518400882022ddcbe1148abf2165917a7b4640 (patch)
tree0cc5f5dcd4b8a8b5d65d8caca317b76599d3f868 /rust/qemu-api/src/lib.rs
parent39c8faefb5e9bf1265cf754f43a17a4ac092d7a3 (diff)
downloadfocaccia-qemu-f3518400882022ddcbe1148abf2165917a7b4640.tar.gz
focaccia-qemu-f3518400882022ddcbe1148abf2165917a7b4640.zip
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>
Diffstat (limited to 'rust/qemu-api/src/lib.rs')
-rw-r--r--rust/qemu-api/src/lib.rs4
1 files changed, 4 insertions, 0 deletions
diff --git a/rust/qemu-api/src/lib.rs b/rust/qemu-api/src/lib.rs
index e6bd953e10..aa8d16ec94 100644
--- a/rust/qemu-api/src/lib.rs
+++ b/rust/qemu-api/src/lib.rs
@@ -32,6 +32,7 @@ unsafe impl Sync for bindings::VMStateInfo {}
 pub mod c_str;
 pub mod definitions;
 pub mod device_class;
+pub mod offset_of;
 pub mod vmstate;
 pub mod zeroable;
 
@@ -169,3 +170,6 @@ unsafe impl GlobalAlloc for QemuAllocator {
         }
     }
 }
+
+#[cfg(has_offset_of)]
+pub use core::mem::offset_of;