qemu-devel
[Top][All Lists]
Advanced

[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.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]