From 3064336053cb3f5440ff7059a08cdc4202df9187 Mon Sep 17 00:00:00 2001 From: Marcel Masque Salgado Date: Tue, 28 Nov 2023 18:36:58 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Removes=20unneeded=20borro?= =?UTF-8?q?ws=20in=20iface=20macro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removes unneeded borrows in the `new` function of the `MethodInfo` struct, and changes the signature of `cfg_attrs` to a slice instead of a Vec. --- zbus_macros/src/iface.rs | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/zbus_macros/src/iface.rs b/zbus_macros/src/iface.rs index 2788b6ebd..e45deabad 100644 --- a/zbus_macros/src/iface.rs +++ b/zbus_macros/src/iface.rs @@ -108,7 +108,7 @@ impl MethodInfo { zbus: &TokenStream, method: &ImplItemMethod, attrs: &MethodAttributes, - cfg_attrs: &Vec<&Attribute>, + cfg_attrs: &[&Attribute], ) -> syn::Result { let is_async = method.sig.asyncness.is_some(); let Signature { @@ -139,16 +139,16 @@ impl MethodInfo { let is_mut = if let FnArg::Receiver(r) = inputs .first() - .ok_or_else(|| Error::new_spanned(&ident, "not &self method"))? + .ok_or_else(|| Error::new_spanned(ident, "not &self method"))? { r.mutability.is_some() } else if is_signal { false } else { - return Err(Error::new_spanned(&method, "missing receiver")); + return Err(Error::new_spanned(method, "missing receiver")); }; if is_signal && !is_async { - return Err(Error::new_spanned(&method, "signals must be async")); + return Err(Error::new_spanned(method, "signals must be async")); } let method_await = if is_async { quote! { .await } @@ -164,7 +164,7 @@ impl MethodInfo { let signal_context_arg: Option = if is_signal { if typed_inputs.is_empty() { return Err(Error::new_spanned( - &inputs, + inputs, "Expected a `&zbus::object_server::SignalContext<'_> argument", )); } @@ -173,11 +173,11 @@ impl MethodInfo { None }; let mut intro_args = quote!(); - intro_args.extend(introspect_input_args(&typed_inputs, is_signal, &cfg_attrs)); + intro_args.extend(introspect_input_args(&typed_inputs, is_signal, cfg_attrs)); let is_result_output = - introspect_add_output_args(&mut intro_args, output, out_args, &cfg_attrs)?; + introspect_add_output_args(&mut intro_args, output, out_args, cfg_attrs)?; - let (args_from_msg, args_names) = get_args_from_inputs(&typed_inputs, &zbus)?; + let (args_from_msg, args_names) = get_args_from_inputs(&typed_inputs, zbus)?; let reply = if is_result_output { let ret = quote!(r); @@ -290,7 +290,7 @@ pub fn expand(args: AttributeArgs, mut input: ItemImpl) -> syn::Result syn::Result syn::Result>` is required). // - // * For all other arg types, we convert the passed value to `OwnedValue` first and - // then pass it as `Value` (so `TryFrom` is required). + // * For all other arg types, we convert the passed value to `OwnedValue` first + // and then pass it as `Value` (so `TryFrom` is required). let value_to_owned = quote! { match ::zbus::zvariant::Value::try_to_owned(value) { ::std::result::Result::Ok(val) => ::zbus::zvariant::Value::from(val),