mirror of
https://git.proxmox.com/git/proxmox
synced 2025-06-14 22:43:46 +00:00
api-macro: add 'flatten' to SerdeAttrib
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
0cdd47c8fc
commit
fbc9be471b
@ -159,12 +159,15 @@ impl TryFrom<&[syn::Attribute]> for ContainerAttrib {
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct SerdeAttrib {
|
pub struct SerdeAttrib {
|
||||||
pub rename: Option<FieldName>,
|
pub rename: Option<FieldName>,
|
||||||
|
pub flatten: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<&[syn::Attribute]> for SerdeAttrib {
|
impl TryFrom<&[syn::Attribute]> for SerdeAttrib {
|
||||||
type Error = syn::Error;
|
type Error = syn::Error;
|
||||||
|
|
||||||
fn try_from(attributes: &[syn::Attribute]) -> Result<Self, syn::Error> {
|
fn try_from(attributes: &[syn::Attribute]) -> Result<Self, syn::Error> {
|
||||||
|
use syn::{Meta, NestedMeta};
|
||||||
|
|
||||||
let mut this: Self = Default::default();
|
let mut this: Self = Default::default();
|
||||||
|
|
||||||
for attrib in attributes {
|
for attrib in attributes {
|
||||||
@ -174,8 +177,8 @@ impl TryFrom<&[syn::Attribute]> for SerdeAttrib {
|
|||||||
|
|
||||||
let args: AttrArgs = syn::parse2(attrib.tokens.clone())?;
|
let args: AttrArgs = syn::parse2(attrib.tokens.clone())?;
|
||||||
for arg in args.args {
|
for arg in args.args {
|
||||||
if let syn::NestedMeta::Meta(syn::Meta::NameValue(var)) = arg {
|
match arg {
|
||||||
if var.path.is_ident("rename") {
|
NestedMeta::Meta(Meta::NameValue(var)) if var.path.is_ident("rename") => {
|
||||||
match var.lit {
|
match var.lit {
|
||||||
syn::Lit::Str(lit) => {
|
syn::Lit::Str(lit) => {
|
||||||
let rename = FieldName::from(&lit);
|
let rename = FieldName::from(&lit);
|
||||||
@ -187,6 +190,10 @@ impl TryFrom<&[syn::Attribute]> for SerdeAttrib {
|
|||||||
_ => error!(var.lit => "'rename' value must be a string literal"),
|
_ => error!(var.lit => "'rename' value must be a string literal"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
NestedMeta::Meta(Meta::Path(path)) if path.is_ident("flatten") => {
|
||||||
|
this.flatten = true;
|
||||||
|
}
|
||||||
|
_ => continue,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user