On Mon, Oct 21, 2024 at 06:35:36PM +0200, Paolo Bonzini wrote:
> Date: Mon, 21 Oct 2024 18:35:36 +0200
> From: Paolo Bonzini <pbonz...@redhat.com>
> Subject: [PATCH v2 11/13] rust: make properties array immutable
> X-Mailer: git-send-email 2.46.2
> 
> Now that device_class_set_props() takes a const pointer, the only part of
> "define_property!" that needs to be non-const is the call to try_into().
> This in turn will only break if offset_of returns a value with the most
> significant bit set (i.e. a struct size that is >=2^31 or >= 2^63,
> respectively on 32- and 64-bit system), which is impossible.
> 
> Just use a cast and clean everything up to remove the run-time
> initialization.  This also removes a use of OnceLock, which was only
> stabilized in 1.70.0.
> 
> Signed-off-by: Paolo Bonzini <pbonz...@redhat.com>
> ---
>  rust/qemu-api/src/device_class.rs | 42 ++++++-------------------------
>  1 file changed, 8 insertions(+), 34 deletions(-)
> 

Very elegant!

Reviewed-by: Zhao Liu <zhao1....@intel.com>


Reply via email to