public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Max R. Carrara" <m.carrara@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH perlmod v2 1/5] macro: function: make argument code generation helpers standalone fns
Date: Fri, 24 Jul 2026 16:49:03 +0200	[thread overview]
Message-ID: <20260724144914.658730-2-m.carrara@proxmox.com> (raw)
In-Reply-To: <20260724144914.658730-1-m.carrara@proxmox.com>

There is not really much of a reason to associate them with
`ArgumentAttrs` from a semantic standpoint, so make those helpers
standalone functions instead.

Signed-off-by: Max R. Carrara <m.carrara@proxmox.com>
---
 perlmod-macro/src/function.rs | 142 +++++++++++++++++-----------------
 1 file changed, 72 insertions(+), 70 deletions(-)

diff --git a/perlmod-macro/src/function.rs b/perlmod-macro/src/function.rs
index 8b5d689..9d4a4af 100644
--- a/perlmod-macro/src/function.rs
+++ b/perlmod-macro/src/function.rs
@@ -86,80 +86,80 @@ impl ArgumentAttrs {
             }
         }
     }
+}
 
-    fn extract_argument_code(
-        &self,
-        span: Span,
-        extracted_name: &Ident,
-        none_handling: TokenStream,
-    ) -> TokenStream {
-        if self.list.is_some() {
-            quote_spanned! { span=>
-                let #extracted_name = args.map(::perlmod::Value::from);
-            }
-        } else {
-            quote_spanned! { span=>
-                let #extracted_name: ::perlmod::Value = match args.next() {
-                    Some(arg) => ::perlmod::Value::from(arg),
-                    None => #none_handling
-                };
-            }
+fn extract_argument_code(
+    arg_attr: &ArgumentAttrs,
+    span: Span,
+    extracted_name: &Ident,
+    none_handling: TokenStream,
+) -> TokenStream {
+    if arg_attr.list.is_some() {
+        quote_spanned! { span=>
+            let #extracted_name = args.map(::perlmod::Value::from);
+        }
+    } else {
+        quote_spanned! { span=>
+            let #extracted_name: ::perlmod::Value = match args.next() {
+                Some(arg) => ::perlmod::Value::from(arg),
+                None => #none_handling
+            };
         }
     }
+}
 
-    fn deserialized_argument_code(
-        &self,
-        span: Span,
-        arg_type: &syn::Type,
-        deserialized_name: &Ident,
-        extracted_name: Ident,
-    ) -> TokenStream {
-        if self.raw {
-            quote_spanned! { span=>
-                let #deserialized_name = #extracted_name;
-            }
-        } else if self.try_from_ref {
-            quote_spanned! { span=>
-                let #deserialized_name: #arg_type =
-                    match ::std::convert::TryFrom::try_from(&#extracted_name) {
-                        Ok(arg) => arg,
-                        Err(err) => {
-                            return Err(::perlmod::Value::new_string(&format!("{err:#}\n"))
-                                .into_mortal()
-                                .into_raw());
-                        }
-                    };
-            }
-        } else if self.list.is_some() {
-            quote_spanned! { span=>
-                let #deserialized_name = {
-                    let _guard = ::perlmod::__private__::InParameterDeserialization::guard();
-                    match <#arg_type as ::perlmod::__private__::serde::Deserialize>::deserialize(
-                        ::perlmod::__private__::serde::de::value::SeqDeserializer::new(
-                            #extracted_name
-                        )
-                    ) {
-                        Ok(arg) => arg,
-                        Err(err) => {
-                            return Err(::perlmod::Value::new_string(&format!("{err:#}\n"))
-                                .into_mortal()
-                                .into_raw());
-                        }
+fn deserialized_argument_code(
+    arg_attr: &ArgumentAttrs,
+    span: Span,
+    arg_type: &syn::Type,
+    deserialized_name: &Ident,
+    extracted_name: Ident,
+) -> TokenStream {
+    if arg_attr.raw {
+        quote_spanned! { span=>
+            let #deserialized_name = #extracted_name;
+        }
+    } else if arg_attr.try_from_ref {
+        quote_spanned! { span=>
+            let #deserialized_name: #arg_type =
+                match ::std::convert::TryFrom::try_from(&#extracted_name) {
+                    Ok(arg) => arg,
+                    Err(err) => {
+                        return Err(::perlmod::Value::new_string(&format!("{err:#}\n"))
+                            .into_mortal()
+                            .into_raw());
+                    }
+                };
+        }
+    } else if arg_attr.list.is_some() {
+        quote_spanned! { span=>
+            let #deserialized_name = {
+                let _guard = ::perlmod::__private__::InParameterDeserialization::guard();
+                match <#arg_type as ::perlmod::__private__::serde::Deserialize>::deserialize(
+                    ::perlmod::__private__::serde::de::value::SeqDeserializer::new(
+                        #extracted_name
+                    )
+                ) {
+                    Ok(arg) => arg,
+                    Err(err) => {
+                        return Err(::perlmod::Value::new_string(&format!("{err:#}\n"))
+                            .into_mortal()
+                            .into_raw());
+                    }
+                }
+            };
+        }
+    } else {
+        quote_spanned! { span=>
+            let #deserialized_name: #arg_type =
+                match ::perlmod::from_ref_value(&#extracted_name) {
+                    Ok(data) => data,
+                    Err(err) => {
+                        return Err(::perlmod::Value::new_string(&format!("{err:#}\n"))
+                            .into_mortal()
+                            .into_raw());
                     }
                 };
-            }
-        } else {
-            quote_spanned! { span=>
-                let #deserialized_name: #arg_type =
-                    match ::perlmod::from_ref_value(&#extracted_name) {
-                        Ok(data) => data,
-                        Err(err) => {
-                            return Err(::perlmod::Value::new_string(&format!("{err:#}\n"))
-                                .into_mortal()
-                                .into_raw());
-                        }
-                    };
-            }
         }
     }
 }
@@ -278,13 +278,15 @@ pub fn handle_function(
             }
         };
 
-        extract_arguments.extend(argument_attrs.extract_argument_code(
+        extract_arguments.extend(extract_argument_code(
+            &argument_attrs,
             span,
             &extracted_name,
             none_handling,
         ));
 
-        deserialized_arguments.extend(argument_attrs.deserialized_argument_code(
+        deserialized_arguments.extend(deserialized_argument_code(
+            &argument_attrs,
             span,
             arg_type,
             &deserialized_name,
-- 
2.47.3





  reply	other threads:[~2026-07-24 14:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24 14:49 [PATCH perlmod v2 0/5] perlmod: add #[hash] parameter attribute Max R. Carrara
2026-07-24 14:49 ` Max R. Carrara [this message]
2026-07-24 14:49 ` [PATCH perlmod v2 2/5] macro: function: make argument attribute handling more extendable Max R. Carrara
2026-07-24 14:49 ` [PATCH perlmod v2 3/5] macro: function: explicitly pass identifier for generated arg iter Max R. Carrara
2026-07-24 14:49 ` [PATCH perlmod v2 4/5] macro: function: move signature inputs handling into helper struct Max R. Carrara
2026-07-24 14:49 ` [PATCH perlmod v2 5/5] perlmod, macro: add #[hash] parameter attribute Max R. Carrara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260724144914.658730-2-m.carrara@proxmox.com \
    --to=m.carrara@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal