From 56806c7e0b516af27f77fdc7e956d03b1c8fa928 Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Khan Date: Thu, 13 Jun 2024 17:53:15 +0200 Subject: [PATCH 1/9] =?UTF-8?q?=F0=9F=9A=A8=20zv:=20Remove=20unnneded=20mu?= =?UTF-8?q?t=20referencing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make clippy happy. --- zvariant/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zvariant/src/lib.rs b/zvariant/src/lib.rs index 3e80b2e66..127cdd9aa 100644 --- a/zvariant/src/lib.rs +++ b/zvariant/src/lib.rs @@ -1165,9 +1165,9 @@ mod tests { let expect_iter = expect.iter().map(|(k, v)| (k, v)).collect::>(); let actual = dict.iter().collect::>(); assert_eq!(actual, expect_iter); - let actual = (&dict).iter().collect::>(); + let actual = dict.iter().collect::>(); assert_eq!(actual, expect_iter); - let actual = (&mut dict).iter().collect::>(); + let actual = dict.iter().collect::>(); assert_eq!(actual, expect_iter); for (_, v) in dict.iter_mut() { if let Value::Str(vv) = v { From 21bf4ac637b183e7805ebdf472fc379454210cd9 Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Khan Date: Thu, 13 Jun 2024 17:55:37 +0200 Subject: [PATCH 2/9] =?UTF-8?q?=F0=9F=9A=A8=20zv:=20max=5Fvalue()=20=3D=3D?= =?UTF-8?q?>=20MAX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Makes latest clippy happy. --- zvariant/src/lib.rs | 48 ++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/zvariant/src/lib.rs b/zvariant/src/lib.rs index 127cdd9aa..a390c7b4b 100644 --- a/zvariant/src/lib.rs +++ b/zvariant/src/lib.rs @@ -820,13 +820,13 @@ mod tests { // Signature: "a(yu(xbxas)s)"); let ar = vec![( // top-most simple fields - u8::max_value(), - u32::max_value(), + u8::MAX, + u32::MAX, ( // 2nd level simple fields - i64::max_value(), + i64::MAX, true, - i64::max_value(), + i64::MAX, // 2nd level array field &["Hello", "World"][..], ), @@ -841,12 +841,12 @@ mod tests { encoded.deserialize().unwrap().0; assert_eq!(decoded.len(), 1); let r = &decoded[0]; - assert_eq!(r.0, u8::max_value()); - assert_eq!(r.1, u32::max_value()); + assert_eq!(r.0, u8::MAX); + assert_eq!(r.1, u32::MAX); let inner_r = &r.2; - assert_eq!(inner_r.0, i64::max_value()); + assert_eq!(inner_r.0, i64::MAX); assert!(inner_r.1); - assert_eq!(inner_r.2, i64::max_value()); + assert_eq!(inner_r.2, i64::MAX); let as_ = &inner_r.3; assert_eq!(as_.len(), 2); assert_eq!(as_[0], "Hello"); @@ -863,12 +863,12 @@ mod tests { gv_encoded.deserialize().unwrap().0; assert_eq!(decoded.len(), 1); let r = &decoded[0]; - assert_eq!(r.0, u8::max_value()); - assert_eq!(r.1, u32::max_value()); + assert_eq!(r.0, u8::MAX); + assert_eq!(r.1, u32::MAX); let inner_r = &r.2; - assert_eq!(inner_r.0, i64::max_value()); + assert_eq!(inner_r.0, i64::MAX); assert!(inner_r.1); - assert_eq!(inner_r.2, i64::max_value()); + assert_eq!(inner_r.2, i64::MAX); let as_ = &inner_r.3; assert_eq!(as_.len(), 2); assert_eq!(as_[0], "Hello"); @@ -883,8 +883,8 @@ mod tests { assert_eq!(variant.n_children(), 1); let r: (u8, u32, (i64, bool, i64, Vec), String) = variant.child_value(0).get().unwrap(); - assert_eq!(r.0, u8::max_value()); - assert_eq!(r.1, u32::max_value()); + assert_eq!(r.0, u8::MAX); + assert_eq!(r.1, u32::MAX); } let ctxt = Context::new_dbus(LE, 0); @@ -900,13 +900,13 @@ mod tests { let r = &array[0]; if let Value::Structure(r) = r { let fields = r.fields(); - assert_eq!(fields[0], Value::U8(u8::max_value())); - assert_eq!(fields[1], Value::U32(u32::max_value())); + assert_eq!(fields[0], Value::U8(u8::MAX)); + assert_eq!(fields[1], Value::U32(u32::MAX)); if let Value::Structure(r) = &fields[2] { let fields = r.fields(); - assert_eq!(fields[0], Value::I64(i64::max_value())); + assert_eq!(fields[0], Value::I64(i64::MAX)); assert_eq!(fields[1], Value::Bool(true)); - assert_eq!(fields[2], Value::I64(i64::max_value())); + assert_eq!(fields[2], Value::I64(i64::MAX)); if let Value::Array(as_) = &fields[3] { assert_eq!(as_.len(), 2); assert_eq!(as_[0], Value::new("Hello")); @@ -940,13 +940,13 @@ mod tests { let r = &array.get(0).unwrap().unwrap(); if let Value::Structure(r) = r { let fields = r.fields(); - assert_eq!(fields[0], Value::U8(u8::max_value())); - assert_eq!(fields[1], Value::U32(u32::max_value())); + assert_eq!(fields[0], Value::U8(u8::MAX)); + assert_eq!(fields[1], Value::U32(u32::MAX)); if let Value::Structure(r) = &fields[2] { let fields = r.fields(); - assert_eq!(fields[0], Value::I64(i64::max_value())); + assert_eq!(fields[0], Value::I64(i64::MAX)); assert_eq!(fields[1], Value::Bool(true)); - assert_eq!(fields[2], Value::I64(i64::max_value())); + assert_eq!(fields[2], Value::I64(i64::MAX)); if let Value::Array(as_) = &fields[3] { assert_eq!(as_.len(), 2); assert_eq!(as_.get(0).unwrap(), Some("Hello")); @@ -972,8 +972,8 @@ mod tests { let child: Variant = variant.child_value(0); let r: (u8, u32, (i64, bool, i64, Vec), String) = child.child_value(0).get().unwrap(); - assert_eq!(r.0, u8::max_value()); - assert_eq!(r.1, u32::max_value()); + assert_eq!(r.0, u8::MAX); + assert_eq!(r.1, u32::MAX); let mut rng = thread_rng(); // Let's test GVariant ser/de of a 254 byte array with variable-width elements as to From fa74f5051cb9be808b25f80f502a0c16575149cb Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Khan Date: Thu, 13 Jun 2024 17:59:57 +0200 Subject: [PATCH 3/9] =?UTF-8?q?=F0=9F=9A=A8=20zv:=20Use=20u8::MAX=20instea?= =?UTF-8?q?d=20of=20std::u8::MAX?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise clippy is unhappy for some strange reason. --- zvariant/src/ser.rs | 2 +- zvariant/src/utils.rs | 14 +++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/zvariant/src/ser.rs b/zvariant/src/ser.rs index da4470c71..f514ed0f9 100644 --- a/zvariant/src/ser.rs +++ b/zvariant/src/ser.rs @@ -29,7 +29,7 @@ impl Write for NullWriteSeek { impl Seek for NullWriteSeek { fn seek(&mut self, _pos: std::io::SeekFrom) -> std::io::Result { - Ok(std::u64::MAX) // should never read the return value! + Ok(u64::MAX) // should never read the return value! } } diff --git a/zvariant/src/utils.rs b/zvariant/src/utils.rs index 5c0ea4f9c..4bff6b7aa 100644 --- a/zvariant/src/utils.rs +++ b/zvariant/src/utils.rs @@ -58,7 +58,7 @@ pub(crate) fn padding_for_n_bytes(value: usize, align: usize) -> usize { pub(crate) fn usize_to_u32(value: usize) -> u32 { assert!( - value <= (std::u32::MAX as usize), + value <= (u32::MAX as usize), "{} too large for `u32`", value, ); @@ -67,21 +67,13 @@ pub(crate) fn usize_to_u32(value: usize) -> u32 { } pub(crate) fn usize_to_u8(value: usize) -> u8 { - assert!( - value <= (std::u8::MAX as usize), - "{} too large for `u8`", - value, - ); + assert!(value <= (u8::MAX as usize), "{} too large for `u8`", value,); value as u8 } pub(crate) fn f64_to_f32(value: f64) -> f32 { - assert!( - value <= (std::f32::MAX as f64), - "{} too large for `f32`", - value, - ); + assert!(value <= (f32::MAX as f64), "{} too large for `f32`", value,); value as f32 } From d14a5d3d9d3bf1fa89fe5d1a8f20ddc0ae201b41 Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Khan Date: Thu, 13 Jun 2024 12:37:09 +0200 Subject: [PATCH 4/9] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20=20zb:=20Fix=20a=20typ?= =?UTF-8?q?o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zbus/src/fdo.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zbus/src/fdo.rs b/zbus/src/fdo.rs index ebd39fc20..4ce7f3586 100644 --- a/zbus/src/fdo.rs +++ b/zbus/src/fdo.rs @@ -827,7 +827,7 @@ assert_impl_all!(DBusProxy<'_>: Send, Sync, Unpin); #[zbus(prefix = "org.freedesktop.DBus.Error", impl_display = true)] #[allow(clippy::upper_case_acronyms)] pub enum Error { - /// Unknown or fall-through ZBus error. + /// Unknown or fall-through zbus error. #[zbus(error)] ZBus(zbus::Error), From 1a1177edccf4d7b9417cbb4ddd65f85853e6bb36 Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Khan Date: Wed, 12 Jun 2024 16:58:24 +0200 Subject: [PATCH 5/9] =?UTF-8?q?=F0=9F=9A=9A=20zm:=20Rename=20an=20internal?= =?UTF-8?q?=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zbus_macros/src/iface.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zbus_macros/src/iface.rs b/zbus_macros/src/iface.rs index 53432c1f7..6c23e1569 100644 --- a/zbus_macros/src/iface.rs +++ b/zbus_macros/src/iface.rs @@ -1115,7 +1115,7 @@ fn introspect_output_arg( ) } -fn get_result_type(p: &TypePath) -> syn::Result<&Type> { +fn get_result_inner_type(p: &TypePath) -> syn::Result<&Type> { if let PathArguments::AngleBracketed(AngleBracketedGenericArguments { args, .. }) = &p .path .segments @@ -1151,7 +1151,7 @@ fn introspect_add_output_args( .ident == "Result"; if is_result_output { - ty = get_result_type(p)?; + ty = get_result_inner_type(p)?; } } @@ -1187,7 +1187,7 @@ fn get_return_type(output: &ReturnType) -> syn::Result<&Type> { .ident == "Result"; if is_result_output { - return get_result_type(p); + return get_result_inner_type(p); } } From 14aba57577d5e514cac2ed4eab456d8ae0262231 Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Khan Date: Thu, 13 Jun 2024 15:01:32 +0200 Subject: [PATCH 6/9] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20=20zm:=20Some=20refact?= =?UTF-8?q?oring=20of=20internal=20interface=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zbus_macros/src/iface.rs | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/zbus_macros/src/iface.rs b/zbus_macros/src/iface.rs index 6c23e1569..62268e75f 100644 --- a/zbus_macros/src/iface.rs +++ b/zbus_macros/src/iface.rs @@ -354,12 +354,7 @@ pub fn expand, M: AttrParse + Into>( let (iface_name, with_spawn, mut proxy) = { let (name, interface, spawn, proxy) = match T::parse_nested_metas(args)?.into() { - ImplAttrs::New(new) => ( - new.name, - new.interface, - new.spawn, - new.proxy.map(|p| Proxy::new(ty, p)), - ), + ImplAttrs::New(new) => (new.name, new.interface, new.spawn, new.proxy), // New proxy attributes are not supported for old `dbus_interface`. ImplAttrs::Old(old) => (old.name, old.interface, old.spawn, None), }; @@ -373,6 +368,7 @@ pub fn expand, M: AttrParse + Into>( "`name` and `interface` attributes should not be specified at the same time", )), }; + let proxy = proxy.map(|p| Proxy::new(ty, &name, p, &zbus)); (name, !spawn.unwrap_or(false), proxy) }; @@ -773,7 +769,7 @@ pub fn expand, M: AttrParse + Into>( } if let Some(proxy) = &mut proxy { - proxy.add_method(info, &properties, &zbus); + proxy.add_method(info, &properties); } } @@ -794,7 +790,7 @@ pub fn expand, M: AttrParse + Into>( } }; - let proxy = proxy.map(|proxy| proxy.gen(&iface_name, &zbus)); + let proxy = proxy.map(|proxy| proxy.gen()); Ok(quote! { #input @@ -1307,6 +1303,10 @@ impl Parse for ImplItemSignal { struct Proxy { // The type name ty: Ident, + // The interface name + iface_name: String, + // The zbus crate + zbus: TokenStream, // Input attrs: ProxyAttributes, @@ -1316,20 +1316,17 @@ struct Proxy { } impl Proxy { - fn new(ty: &Ident, attrs: ProxyAttributes) -> Self { + fn new(ty: &Ident, iface_name: &str, attrs: ProxyAttributes, zbus: &TokenStream) -> Self { Self { + iface_name: iface_name.to_string(), ty: ty.clone(), + zbus: zbus.clone(), attrs, methods: quote!(), } } - fn add_method( - &mut self, - method_info: MethodInfo, - properties: &BTreeMap>, - zbus: &TokenStream, - ) { + fn add_method(&mut self, method_info: MethodInfo, properties: &BTreeMap>) { let inputs: Punctuated = method_info .typed_inputs .iter() @@ -1386,6 +1383,7 @@ impl Proxy { } } let cfg_attrs = method_info.cfg_attrs; + let zbus = &self.zbus; self.methods.extend(quote! { #(#cfg_attrs)* #[zbus(#proxy_method_attrs)] @@ -1393,7 +1391,7 @@ impl Proxy { }); } - fn gen(&self, iface_name: &str, zbus: &TokenStream) -> TokenStream { + fn gen(&self) -> TokenStream { let attrs = &self.attrs; let ( assume_defaults, @@ -1432,6 +1430,8 @@ impl Proxy { &self.ty, &self.methods, ); + let iface_name = &self.iface_name; + let zbus = &self.zbus; quote! { #[#zbus::proxy( name = #iface_name, From b50e7a411b87014f8324b75baf23310c7092a8ff Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Khan Date: Thu, 13 Jun 2024 15:01:54 +0200 Subject: [PATCH 7/9] =?UTF-8?q?=F0=9F=93=9D=20zm:=20Autogenerate=20docs=20?= =?UTF-8?q?for=20proxy=20struct=20generated=20by=20interface=20macro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zbus_macros/src/iface.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zbus_macros/src/iface.rs b/zbus_macros/src/iface.rs index 62268e75f..10f56edad 100644 --- a/zbus_macros/src/iface.rs +++ b/zbus_macros/src/iface.rs @@ -1432,7 +1432,9 @@ impl Proxy { ); let iface_name = &self.iface_name; let zbus = &self.zbus; + let proxy_doc = format!("Proxy for the `{iface_name}` interface."); quote! { + #[doc = #proxy_doc] #[#zbus::proxy( name = #iface_name, #assume_defaults From aae9fe436084484e5cf5ebfeedd99f27dd09784d Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Khan Date: Thu, 13 Jun 2024 15:29:41 +0200 Subject: [PATCH 8/9] =?UTF-8?q?=E2=9C=A8=20interface=20to=20forward=20doc?= =?UTF-8?q?=20attributes=20to=20proxy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zbus_macros/src/iface.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/zbus_macros/src/iface.rs b/zbus_macros/src/iface.rs index 10f56edad..f98e6d8fb 100644 --- a/zbus_macros/src/iface.rs +++ b/zbus_macros/src/iface.rs @@ -169,6 +169,8 @@ struct MethodInfo { output: ReturnType, /// The cfg attributes of the method. cfg_attrs: Vec, + /// The doc attributes of the method. + doc_attrs: Vec, } impl MethodInfo { @@ -177,6 +179,7 @@ impl MethodInfo { method: &ImplItemFn, attrs: &MethodAttrs, cfg_attrs: &[&Attribute], + doc_attrs: &[&Attribute], ) -> syn::Result { let is_async = method.sig.asyncness.is_some(); let Signature { @@ -319,6 +322,7 @@ impl MethodInfo { proxy_attrs, output: output.clone(), cfg_attrs: cfg_attrs.iter().cloned().cloned().collect(), + doc_attrs: doc_attrs.iter().cloned().cloned().collect(), }) } } @@ -420,8 +424,13 @@ pub fn expand, M: AttrParse + Into>( .iter() .filter(|a| a.path().is_ident("cfg")) .collect(); + let doc_attrs: Vec<_> = method + .attrs + .iter() + .filter(|a| a.path().is_ident("doc")) + .collect(); - let method_info = MethodInfo::new(&zbus, method, &attrs, &cfg_attrs)?; + let method_info = MethodInfo::new(&zbus, method, &attrs, &cfg_attrs, &doc_attrs)?; let attr_property = match attrs { MethodAttrs::Old(o) => o.property.map(|op| PropertyAttributes { emits_changed_signal: op.emits_changed_signal, @@ -1384,8 +1393,10 @@ impl Proxy { } let cfg_attrs = method_info.cfg_attrs; let zbus = &self.zbus; + let doc_attrs = method_info.doc_attrs; self.methods.extend(quote! { #(#cfg_attrs)* + #(#doc_attrs)* #[zbus(#proxy_method_attrs)] fn #ident(&self, #inputs) -> #zbus::Result<#ret>; }); From 9d80a638b68661479757c8d6d15846000bfeae20 Mon Sep 17 00:00:00 2001 From: Zeeshan Ali Khan Date: Thu, 13 Jun 2024 16:24:28 +0200 Subject: [PATCH 9/9] =?UTF-8?q?=F0=9F=9A=91=EF=B8=8F=20zm:=20Don't=20skip?= =?UTF-8?q?=20the=20first=20arg=20of=20signal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `SignalContext` argument of interface signals are already filtered out so we were ending up filtering it twice and therefore the real first argument. --- zbus_macros/src/iface.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/zbus_macros/src/iface.rs b/zbus_macros/src/iface.rs index f98e6d8fb..8dd29dbc3 100644 --- a/zbus_macros/src/iface.rs +++ b/zbus_macros/src/iface.rs @@ -1339,17 +1339,11 @@ impl Proxy { let inputs: Punctuated = method_info .typed_inputs .iter() - .enumerate() - .filter(|(idx, input)| { - if method_info.method_type == MethodType::Signal { - // Skip the `SignalContext` argument. - return *idx != 0; - } - + .filter(|input| { let a = ArgAttributes::parse(&input.attrs).unwrap(); !a.object_server && !a.connection && !a.header && !a.signal_context }) - .map(|(_, p)| p.clone()) + .cloned() .collect(); let ret = get_return_type(&method_info.output) .map(|r| quote!(#r))