mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-30 22:03:54 -06:00
rust: qemu_api_macros: add Wrapper derive macro
Add a derive macro that makes it easy to peel off all the layers of specialness (UnsafeCell, MaybeUninit, etc.) and just get a pointer to the wrapped type; and likewise add them back starting from a *mut. Reviewed-by: Zhao Liu <zhao1.liu@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
0b9d05e3c9
commit
f07a5674cf
4 changed files with 141 additions and 9 deletions
|
@ -315,11 +315,13 @@ a raw pointer, for use in calls to C functions. It can be used for
|
|||
example as follows::
|
||||
|
||||
#[repr(transparent)]
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, qemu_api_macros::Wrapper)]
|
||||
pub struct Object(Opaque<bindings::Object>);
|
||||
|
||||
The bindings will then manually check for the big QEMU lock with
|
||||
assertions, which allows the wrapper to be declared thread-safe::
|
||||
where the special ``derive`` macro provides useful methods such as
|
||||
``from_raw``, ``as_ptr`, ``as_mut_ptr`` and ``raw_get``. The bindings will
|
||||
then manually check for the big QEMU lock with assertions, which allows
|
||||
the wrapper to be declared thread-safe::
|
||||
|
||||
unsafe impl Send for Object {}
|
||||
unsafe impl Sync for Object {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue