[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 04/10] rust: callbacks: allow passing optional callbacks as (
From: |
Zhao Liu |
Subject: |
Re: [PATCH 04/10] rust: callbacks: allow passing optional callbacks as () |
Date: |
Mon, 27 Jan 2025 16:41:40 +0800 |
> Date: Fri, 17 Jan 2025 20:39:57 +0100
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH 04/10] rust: callbacks: allow passing optional callbacks as
> ()
> X-Mailer: git-send-email 2.47.1
>
> In some cases, callbacks are optional. Using "Some(function)" and "None"
> does not work well, because when someone writes "None" the compiler does
> not know what to use for "F" in "Option<F>".
>
> Therefore, adopt () to mean a "null" callback. It is possible to enforce
> that a callback is valid by adding a "let _: () = F::ASSERT_IS_SOME" before
> the invocation of F::call.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> rust/qemu-api/src/callbacks.rs | 97 ++++++++++++++++++++++++++++++++++
> 1 file changed, 97 insertions(+)
Awesome trick.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
> + /// Referring to this constant asserts that the `Self` type is an actual
> + /// function type, which can be used to catch incorrect use of `()`
> + /// at compile time.
An extra whitespace.
- [RFC PATCH 00/10] rust: remaining part of qdev bindings, Paolo Bonzini, 2025/01/17
- [PATCH 01/10] rust: qemu-api: add sub-subclass to the integration tests, Paolo Bonzini, 2025/01/17
- [PATCH 02/10] rust: qom: add reference counting functionality, Paolo Bonzini, 2025/01/17
- [PATCH 03/10] rust: qom: add object creation functionality, Paolo Bonzini, 2025/01/17
- [PATCH 04/10] rust: callbacks: allow passing optional callbacks as (), Paolo Bonzini, 2025/01/17
- Re: [PATCH 04/10] rust: callbacks: allow passing optional callbacks as (),
Zhao Liu <=
- [PATCH 06/10] rust: qom: allow initializing interface vtables, Paolo Bonzini, 2025/01/17
- [PATCH 07/10] rust: qdev: make ObjectImpl a supertrait of DeviceImpl, Paolo Bonzini, 2025/01/17
- [PATCH 05/10] rust: qdev: add clock creation, Paolo Bonzini, 2025/01/17
- [PATCH 09/10] rust: bindings: add Sync markers to types referred to by MemoryRegionOps, Paolo Bonzini, 2025/01/17
- [PATCH 08/10] rust: qdev: switch from legacy reset to Resettable, Paolo Bonzini, 2025/01/17