aboutsummaryrefslogtreecommitdiff
path: root/rust/qemu-api/src/prelude.rs
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2024-12-08 12:16:56 +0100
committerPaolo Bonzini <pbonzini@redhat.com>2025-01-23 11:50:53 +0100
commit0d43ddae35a29d1822ec3f35a31bfe7c91618ef4 (patch)
tree9fc4175e611650c4e41567acf48d3370925ba1bd /rust/qemu-api/src/prelude.rs
parent57f9d9c84a9112d534fa90f2a6dad74bd71150b6 (diff)
downloadqemu-0d43ddae35a29d1822ec3f35a31bfe7c91618ef4.zip
qemu-0d43ddae35a29d1822ec3f35a31bfe7c91618ef4.tar.gz
qemu-0d43ddae35a29d1822ec3f35a31bfe7c91618ef4.tar.bz2
rust: vmstate: add new type safe implementation
The existing translation of the C macros for vmstate does not make any attempt to type-check vmstate declarations against the struct, so introduce a new system that computes VMStateField based on the actual struct declaration. Macros do not have full access to the type system, therefore a full implementation of this scheme requires a helper trait to analyze the type and produce a VMStateField from it; a macro "vmstate_of!" accepts arguments similar to "offset_of!" and tricks the compiler into looking up the trait for the right type. The patch introduces not just vmstate_of!, but also the slightly too clever enabling macro call_func_with_field!. The particular trick used here was proposed on the users.rust-lang.org forum, so I take no merit and all the blame. Introduce the trait and some functions to access it; the actual implementation comes later. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'rust/qemu-api/src/prelude.rs')
-rw-r--r--rust/qemu-api/src/prelude.rs2
1 files changed, 2 insertions, 0 deletions
diff --git a/rust/qemu-api/src/prelude.rs b/rust/qemu-api/src/prelude.rs
index 4ea70b9..2dc86e1 100644
--- a/rust/qemu-api/src/prelude.rs
+++ b/rust/qemu-api/src/prelude.rs
@@ -18,3 +18,5 @@ pub use crate::qom::ObjectType;
pub use crate::qom_isa;
pub use crate::sysbus::SysBusDeviceMethods;
+
+pub use crate::vmstate::VMState;