unsafe impl<T: Sync> Sync for VMStateDescription<T> {}
#[derive(Clone)]
-pub struct VMStateDescriptionBuilder<T>(bindings::VMStateDescription, PhantomData<fn(&T)>);
+pub struct VMStateDescriptionBuilder<T>(
+ bindings::VMStateDescription,
+ Option<*const std::os::raw::c_char>, // the name of VMStateDescription
+ PhantomData<fn(&T)>,
+);
#[derive(Debug)]
pub struct InvalidError;
impl<T> VMStateDescriptionBuilder<T> {
#[must_use]
pub const fn name(mut self, name_str: &CStr) -> Self {
- self.0.name = ::std::ffi::CStr::as_ptr(name_str);
+ self.1 = Some(::std::ffi::CStr::as_ptr(name_str));
self
}
}
#[must_use]
- pub const fn build(self) -> VMStateDescription<T> {
+ pub const fn build(mut self) -> VMStateDescription<T> {
+ // FIXME: is_null()/as_ref() become const since v1.84.
+ assert!(self.1.is_some(), "VMStateDescription requires name field!");
+ self.0.name = self.1.unwrap();
VMStateDescription::<T>(self.0, PhantomData)
}
#[must_use]
pub const fn new() -> Self {
- Self(bindings::VMStateDescription::ZERO, PhantomData)
+ Self(bindings::VMStateDescription::ZERO, None, PhantomData)
}
}