qemu/rust/qemu-api/src
Zhao Liu b131003721 rust/vmstate: Support vmstate_validate
In C version, VMSTATE_VALIDATE accepts the function pointer, which is
used to check if some conditions of structure could meet, although the
C version macro doesn't accept any structure as the opaque type.

But it's hard to integrate VMSTATE_VALIDAE into vmstate_struct, a new
macro has to be introduced to specifically handle the case corresponding
to VMSTATE_VALIDATE.

One of the difficulties is inferring the type of a callback by its name
`test_fn`. We can't directly use `test_fn` as a parameter of
test_cb_builder__() to get its type "F", because in this way, Rust
compiler will be too conservative on drop check and complain "the
destructor for this type cannot be evaluated in constant functions".

Fortunately, PhantomData<T> could help in this case, because it is
considered to never have a destructor, no matter its field type [*].

The `phantom__()` in the `call_func_with_field` macro provides a good
example of using PhantomData to infer type. So copy this idea and apply
it to the `vmstate_validate` macro.

[*]: https://doc.rust-lang.org/std/ops/trait.Drop.html#drop-check

Signed-off-by: Zhao Liu <zhao1.liu@intel.com>
Link: https://lore.kernel.org/r/20250318130219.1799170-11-zhao1.liu@intel.com
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-03-21 12:56:00 +01:00
..
assertions.rs rust/vmstate: Fix type check for varray in vmstate_struct 2025-03-21 12:56:00 +01:00
bindings.rs rust: bindings: remove more unnecessary Send/Sync impls 2025-03-06 12:44:47 +01:00
bitops.rs rust: add a bit operation module 2024-12-10 18:49:26 +01:00
c_str.rs rust: qemu_api: add a documentation header for all modules 2025-02-13 12:51:34 +01:00
callbacks.rs rust: callbacks: allow passing optional callbacks as () 2025-02-13 12:19:33 +01:00
cell.rs rust: cell: add full example of declaring a SysBusDevice 2025-03-06 12:44:47 +01:00
chardev.rs rust: chardev: provide basic bindings to character devices 2025-03-06 12:44:47 +01:00
errno.rs rust: add module to convert between success/-errno and io::Result 2025-02-25 16:18:08 +01:00
irq.rs rust: irq: wrap IRQState with Opaque<> 2025-03-06 12:44:46 +01:00
lib.rs rust: add module to convert between success/-errno and io::Result 2025-02-25 16:18:08 +01:00
memory.rs rust: qom: remove operations on &mut 2025-03-06 12:44:47 +01:00
module.rs rust: rename qemu-api modules to follow C code a bit more 2024-12-19 19:36:37 +01:00
offset_of.rs rust: qemu_api: add a documentation header for all modules 2025-02-13 12:51:34 +01:00
prelude.rs rust: qom: remove operations on &mut 2025-03-06 12:44:47 +01:00
qdev.rs rust: chardev: wrap Chardev with Opaque<> 2025-03-06 12:44:47 +01:00
qom.rs rust: qom: remove operations on &mut 2025-03-06 12:44:47 +01:00
sysbus.rs rust: sysbus: wrap SysBusDevice with Opaque<> 2025-03-06 12:44:47 +01:00
timer.rs rust: timer: wrap QEMUTimer with Opaque<> and express pinning requirements 2025-03-06 12:44:46 +01:00
vmstate.rs rust/vmstate: Support vmstate_validate 2025-03-21 12:56:00 +01:00
zeroable.rs rust: chardev: provide basic bindings to character devices 2025-03-06 12:44:47 +01:00