mirror of
https://git.proxmox.com/git/proxmox
synced 2025-08-06 15:02:46 +00:00
api-macro: enums: sort OneOf variants
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
d38ce91384
commit
a36f0f3bf9
@ -206,7 +206,7 @@ fn handle_section_config_enum(
|
|||||||
bail!(name => r#"SectionConfig enum needs a `#[serde(tag = "...")]` container attribute"#);
|
bail!(name => r#"SectionConfig enum needs a `#[serde(tag = "...")]` container attribute"#);
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut variants = TokenStream::new();
|
let mut variants = Vec::new();
|
||||||
let mut register_sections = TokenStream::new();
|
let mut register_sections = TokenStream::new();
|
||||||
let mut to_type = TokenStream::new();
|
let mut to_type = TokenStream::new();
|
||||||
for variant in &mut enum_ty.variants {
|
for variant in &mut enum_ty.variants {
|
||||||
@ -235,12 +235,15 @@ fn handle_section_config_enum(
|
|||||||
|
|
||||||
let variant_ident = &variant.ident;
|
let variant_ident = &variant.ident;
|
||||||
let ty = &field.ty;
|
let ty = &field.ty;
|
||||||
variants.extend(quote_spanned! { variant.ident.span() =>
|
variants.push((
|
||||||
(
|
variant_string.value(),
|
||||||
#variant_string,
|
quote_spanned! { variant.ident.span() =>
|
||||||
&<#ty as ::proxmox_schema::ApiType>::API_SCHEMA,
|
(
|
||||||
),
|
#variant_string,
|
||||||
});
|
&<#ty as ::proxmox_schema::ApiType>::API_SCHEMA,
|
||||||
|
),
|
||||||
|
},
|
||||||
|
));
|
||||||
register_sections.extend(quote_spanned! { variant.ident.span() =>
|
register_sections.extend(quote_spanned! { variant.ident.span() =>
|
||||||
this.register_plugin(
|
this.register_plugin(
|
||||||
::proxmox_section_config::SectionConfigPlugin::new(
|
::proxmox_section_config::SectionConfigPlugin::new(
|
||||||
@ -261,6 +264,11 @@ fn handle_section_config_enum(
|
|||||||
Self::#variant_ident(_) => #variant_string,
|
Self::#variant_ident(_) => #variant_string,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
variants.sort_by(|a, b| a.0.cmp(&b.0));
|
||||||
|
let variants = variants
|
||||||
|
.into_iter()
|
||||||
|
.map(|(_name, def)| def)
|
||||||
|
.collect::<TokenStream>();
|
||||||
|
|
||||||
Ok(quote_spanned! { name.span() =>
|
Ok(quote_spanned! { name.span() =>
|
||||||
#enum_ty
|
#enum_ty
|
||||||
|
Loading…
Reference in New Issue
Block a user