On Tue, Dec 17, 2024 at 05:40:14PM +0100, Paolo Bonzini wrote: > Date: Tue, 17 Dec 2024 17:40:14 +0100 > From: Paolo Bonzini <pbonz...@redhat.com> > Subject: Re: [PATCH 26/26] rust: callbacks: allow passing optional > callbacks as () > > Il mar 17 dic 2024, 16:55 Zhao Liu <zhao1....@intel.com> ha scritto: > > > 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 <pbonz...@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>. > > > > You wouldn't use Option<callback> at all, using () instead of None; the > difference is that () does not have a parameter while None does (and the > compiler cannot infer it). But I am okay with leaving this patch behind > until there's a need.
Am I using the wrong terminology? Function pointers in a structure should be called a vtable, rather than callbacks (for example, methods in TypeInfo, read/write methods in MemoryRegionOps). Callbacks are typically function pointers used as function parameters (for example, timer/gpio). So, is the callback implementation here only used for the latter case? Thanks, Zhao