> +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) }; And I think all the other callbacks need to be checked as well. > + self.0.pre_load = Some(vmstate_pre_load_cb::<T, F>); > + self > + } Thank you :-) ! And though it's a preview, Reviewed-by: Zhao Liu <zhao1....@intel.com>