[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 26/26] rust: callbacks: allow passing optional callbacks as (
From: |
Zhao Liu |
Subject: |
Re: [PATCH 26/26] rust: callbacks: allow passing optional callbacks as () |
Date: |
Wed, 18 Dec 2024 00:13:32 +0800 |
On Mon, Dec 09, 2024 at 01:37:17PM +0100, Paolo Bonzini wrote:
> Date: Mon, 9 Dec 2024 13:37:17 +0100
> From: Paolo Bonzini <pbonzini@redhat.com>
> Subject: [PATCH 26/26] 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>".
I understand the direct use case is MemoryRegionOps, which has optional
callbacks. However, I'm not quite sure how exactly it should be applied
to C bindings and how it will play with Option<callback>.
Could u pls provide a simple example?
> 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(+)
>
> diff --git a/rust/qemu-api/src/callbacks.rs b/rust/qemu-api/src/callbacks.rs
> index 6401d807198..83c681d6478 100644
> --- a/rust/qemu-api/src/callbacks.rs
> +++ b/rust/qemu-api/src/callbacks.rs
> @@ -76,6 +76,31 @@
> /// call_it(&move |_| String::from(x), "hello workd");
typo: s/workd/word/ (in previous patch :-))
Re: [PATCH 24/26] rust: qom: move device_id to PL011 class side, Zhao Liu, 2024/12/18
[PATCH 23/26] rust: qom: add initial subset of methods on Object, Paolo Bonzini, 2024/12/09
[PATCH 21/26] rust: tests: allow writing more than one test, Paolo Bonzini, 2024/12/09
[PATCH 26/26] rust: callbacks: allow passing optional callbacks as (), Paolo Bonzini, 2024/12/09
- Re: [PATCH 26/26] rust: callbacks: allow passing optional callbacks as (),
Zhao Liu <=
[PATCH 18/26] rust: qom: add possibility of overriding unparent, Paolo Bonzini, 2024/12/09
[PATCH 25/26] rust: qemu-api: add a module to wrap functions and zero-sized closures, Paolo Bonzini, 2024/12/09
[PATCH 22/26] rust: qom: add casting functionality, Paolo Bonzini, 2024/12/09