From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 58CBD1FF0E6 for ; Fri, 24 Jul 2026 16:49:27 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 4D4BF21554; Fri, 24 Jul 2026 16:49:21 +0200 (CEST) From: "Max R. Carrara" 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 Message-ID: <20260724144914.658730-2-m.carrara@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260724144914.658730-1-m.carrara@proxmox.com> References: <20260724144914.658730-1-m.carrara@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1784904526172 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.031 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_LOW -0.7 Sender listed at https://www.dnswl.org/, low trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: CXSPTIHC34Z2NFVM5SXQBTXKN5YYYFYR X-Message-ID-Hash: CXSPTIHC34Z2NFVM5SXQBTXKN5YYYFYR X-MailFrom: m.carrara@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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