On Tue, May 6, 2025 at 11:35 AM Zhao Liu <zhao1....@intel.com> wrote:
>
> > +unsafe extern "C" fn vmstate_pre_load_cb<
> > +    T,
> > +    F: for<'a> FnCall<(&'a T,), Result<(), impl Into<Errno>>>,
> > +>(
> > +    opaque: *mut c_void,
> > +) -> c_int {
> > +    // SAFETY: assumes vmstate_struct! is used correctly
> > +    let result = F::call((unsafe { &*(opaque.cast::<T>()) },));
> > +    into_neg_errno(result)
>
> Thanks! Now I see why you used io::ErrorKind.
>
> > +}
>
> ...
>
> > +    #[must_use]
> > +    pub const fn pre_load<F: for<'a> FnCall<(&'a T,), Result<(), impl 
> > Into<Errno>>>>(
> > +        mut self,
> > +        _f: &F,
> > +    ) -> Self {
>
> Do we need to assert F is not ()?
>
> const { assert!(F::IS_SOME) };

A NULL callback (i.e. ".pre_load(())") is a bit weird but acceptable.
So the assertion if not needed, but indeed there should be an "if"
that stores "ptr::null()" instead of vmstate_pre_load_cb::<F>.

Paolo


Reply via email to