]> git.ipfire.org Git - thirdparty/qemu.git/commit
rust: callbacks: allow passing optional callbacks as ()
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 6 Dec 2024 16:08:49 +0000 (17:08 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Thu, 13 Feb 2025 11:19:33 +0000 (12:19 +0100)
commit66bcc554d27f693f89bf04df24d474463a90a894
tree1bce253895e365cdef36ee57e1af50607159cbdd
parentec3eba98967014f942bafb4307303d853d96e7e7
rust: callbacks: allow passing optional callbacks as ()

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.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
rust/qemu-api/src/callbacks.rs