[pbs-devel] [PATCH proxmox 06/18] api-macro: add 'flatten' to SerdeAttrib

Wolfgang Bumiller w.bumiller at proxmox.com
Fri Dec 18 12:25:54 CET 2020


Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 proxmox-api-macro/src/serde.rs | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/proxmox-api-macro/src/serde.rs b/proxmox-api-macro/src/serde.rs
index a08f461..2829030 100644
--- a/proxmox-api-macro/src/serde.rs
+++ b/proxmox-api-macro/src/serde.rs
@@ -159,12 +159,15 @@ impl TryFrom<&[syn::Attribute]> for ContainerAttrib {
 #[derive(Default)]
 pub struct SerdeAttrib {
     pub rename: Option<FieldName>,
+    pub flatten: bool,
 }
 
 impl TryFrom<&[syn::Attribute]> for SerdeAttrib {
     type Error = syn::Error;
 
     fn try_from(attributes: &[syn::Attribute]) -> Result<Self, syn::Error> {
+        use syn::{Meta, NestedMeta};
+
         let mut this: Self = Default::default();
 
         for attrib in attributes {
@@ -174,8 +177,8 @@ impl TryFrom<&[syn::Attribute]> for SerdeAttrib {
 
             let args: AttrArgs = syn::parse2(attrib.tokens.clone())?;
             for arg in args.args {
-                if let syn::NestedMeta::Meta(syn::Meta::NameValue(var)) = arg {
-                    if var.path.is_ident("rename") {
+                match arg {
+                    NestedMeta::Meta(Meta::NameValue(var)) if var.path.is_ident("rename") => {
                         match var.lit {
                             syn::Lit::Str(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"),
                         }
                     }
+                    NestedMeta::Meta(Meta::Path(path)) if path.is_ident("flatten") => {
+                        this.flatten = true;
+                    }
+                    _ => continue,
                 }
             }
         }
-- 
2.20.1





More information about the pbs-devel mailing list