mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-02 12:33:30 +00:00
default to not serializing None options
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
d9f57ed107
commit
cb2c260f87
@ -527,7 +527,9 @@ fn handle_struct_named(
|
||||
field_ident_list.extend(quote_spanned! { field_span => #field_ident, });
|
||||
|
||||
serialize_entries.extend(quote_spanned! { field_span =>
|
||||
state.serialize_field(#field_str, &self.#field_ident)?;
|
||||
if !::proxmox::api::ApiType::should_skip_serialization(&self.#field_ident) {
|
||||
state.serialize_field(#field_str, &self.#field_ident)?;
|
||||
}
|
||||
});
|
||||
|
||||
field_option_init_list.extend(quote_spanned! { field_span =>
|
||||
|
@ -185,6 +185,10 @@ pub trait ApiType {
|
||||
fn get_type_info(&self) -> &'static TypeInfo {
|
||||
Self::type_info()
|
||||
}
|
||||
|
||||
fn should_skip_serialization(&self) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// Option types are supposed to wrap their underlying types with an `optional:` text in their
|
||||
@ -234,6 +238,10 @@ impl<T: ApiType> ApiType for Option<T> {
|
||||
unsafe { (*DATA.info.as_ptr()).as_ref().unwrap() }
|
||||
*/
|
||||
}
|
||||
|
||||
fn should_skip_serialization(&self) -> bool {
|
||||
self.is_none()
|
||||
}
|
||||
}
|
||||
|
||||
/// Any `Result<T, Error>` of course gets the same info as `T`, since this only means that it can
|
||||
|
Loading…
Reference in New Issue
Block a user