diff --git a/book/src/client.md b/book/src/client.md index 20e84e043..d0a0483d9 100644 --- a/book/src/client.md +++ b/book/src/client.md @@ -258,7 +258,7 @@ async fn main() -> Result<()> { let props = zbus::fdo::PropertiesProxy::builder(&conn) .destination("org.freedesktop.GeoClue2")? - .path(client.path())? + .path(client.inner().path())? .build() .await?; let mut props_changed = props.receive_properties_changed().await?; diff --git a/zbus/src/blocking/object_server.rs b/zbus/src/blocking/object_server.rs index 74657c4de..bdc004774 100644 --- a/zbus/src/blocking/object_server.rs +++ b/zbus/src/blocking/object_server.rs @@ -1,7 +1,5 @@ //! The object server API. -use std::ops::Deref; - use static_assertions::assert_impl_all; use zvariant::ObjectPath; @@ -235,14 +233,6 @@ impl ObjectServer { } } -impl Deref for ObjectServer { - type Target = crate::ObjectServer; - - fn deref(&self) -> &Self::Target { - self.inner() - } -} - impl From for ObjectServer { fn from(azync: crate::ObjectServer) -> Self { Self { azync } diff --git a/zbus/src/connection/builder.rs b/zbus/src/connection/builder.rs index 64e9960da..c489eee56 100644 --- a/zbus/src/connection/builder.rs +++ b/zbus/src/connection/builder.rs @@ -383,7 +383,9 @@ impl<'a> Builder<'a> { let object_server = conn.sync_object_server(false, None); for (path, interfaces) in self.interfaces { for (name, iface) in interfaces { - let future = object_server.at_ready(path.to_owned(), name, || iface); + let future = object_server + .inner() + .at_ready(path.to_owned(), name, || iface); let added = future.await?; // Duplicates shouldn't happen. assert!(added); diff --git a/zbus/src/proxy/mod.rs b/zbus/src/proxy/mod.rs index 266750a0e..abba7a6e4 100644 --- a/zbus/src/proxy/mod.rs +++ b/zbus/src/proxy/mod.rs @@ -332,11 +332,12 @@ impl PropertiesCache { let prop_changes = proxy.receive_properties_changed().await?.map(Either::Left); let get_all = proxy + .inner() .connection() .call_method_raw( - Some(proxy.destination()), - proxy.path(), - Some(proxy.interface()), + Some(proxy.inner().destination()), + proxy.inner().path(), + Some(proxy.inner().interface()), "GetAll", BitFlags::empty(), &interface, @@ -1358,17 +1359,18 @@ mod tests { let proxy = fdo::DBusProxy::new(&dest_conn).await?; let mut name_acquired_stream = proxy + .inner() .receive_signal_with_args("NameAcquired", &[(0, well_known)]) .await?; - let prop_stream = - proxy - .receive_property_changed("SomeProp") - .await - .filter_map(|changed| async move { - let v: Option = changed.get().await.ok(); - dbg!(v) - }); + let prop_stream = proxy + .inner() + .receive_property_changed("SomeProp") + .await + .filter_map(|changed| async move { + let v: Option = changed.get().await.ok(); + dbg!(v) + }); drop(proxy); drop(prop_stream); diff --git a/zbus/tests/e2e.rs b/zbus/tests/e2e.rs index 22e6256b6..0faaad0c2 100644 --- a/zbus/tests/e2e.rs +++ b/zbus/tests/e2e.rs @@ -685,7 +685,7 @@ async fn my_iface_test(conn: Connection, event: Event) -> zbus::Result { assert_eq!(proxy.optional_property().await?, Some(42).into()); - let xml = proxy.introspect().await?; + let xml = proxy.inner().introspect().await?; debug!("Introspection: {}", xml); let node = zbus_xml::Node::from_reader(xml.as_bytes()).map_err(|e| Error::Failure(e.to_string()))?; @@ -761,7 +761,7 @@ async fn my_iface_test(conn: Connection, event: Event) -> zbus::Result { // TODO: Check if the properties are correct. // issue#207: interface panics on incorrect number of args. - assert!(proxy.call_method("CreateObj", &()).await.is_err()); + assert!(proxy.inner().call_method("CreateObj", &()).await.is_err()); let my_obj_proxy = MyIfaceProxy::builder(&conn) .destination("org.freedesktop.MyService")? @@ -776,7 +776,7 @@ async fn my_iface_test(conn: Connection, event: Event) -> zbus::Result { assert_eq!(my_obj_proxy.count().await?, 0); assert_eq!(my_obj_proxy.cached_count()?, Some(0)); assert_eq!( - my_obj_proxy.cached_property_raw("Count").as_deref(), + my_obj_proxy.inner().cached_property_raw("Count").as_deref(), Some(&Value::from(0u32)) ); my_obj_proxy.ping().await?; @@ -801,12 +801,13 @@ async fn my_iface_test(conn: Connection, event: Event) -> zbus::Result { assert_eq!(args.object_path(), "/zbus/test/MyObj"); assert_eq!(args.interfaces(), &["org.freedesktop.MyIface"]); - assert!(my_obj_proxy.introspect().await.is_err()); + assert!(my_obj_proxy.inner().introspect().await.is_err()); assert!(my_obj_proxy.ping().await.is_err()); // Make sure methods modifying the ObjectServer can be called without // deadlocks. proxy + .inner() .call_method("CreateObjInside", &("CreatedInside")) .await?; let created_inside_proxy = MyIfaceProxy::builder(&conn) diff --git a/zbus_macros/src/proxy.rs b/zbus_macros/src/proxy.rs index 41080f253..e832039cf 100644 --- a/zbus_macros/src/proxy.rs +++ b/zbus_macros/src/proxy.rs @@ -374,6 +374,11 @@ pub fn create_proxy( &self.0 } + /// The mutable reference to the underlying `zbus::Proxy`. + pub fn inner_mut(&mut self) -> &mut #proxy_struct<'p> { + &mut self.0 + } + #methods } @@ -397,29 +402,15 @@ pub fn create_proxy( } } - impl<'p> ::std::ops::Deref for #proxy_name<'p> { - type Target = #proxy_struct<'p>; - - fn deref(&self) -> &Self::Target { - &self.0 - } - } - - impl<'p> ::std::ops::DerefMut for #proxy_name<'p> { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } - } - impl<'p> ::std::convert::AsRef<#proxy_struct<'p>> for #proxy_name<'p> { fn as_ref(&self) -> &#proxy_struct<'p> { - &*self + self.inner() } } impl<'p> ::std::convert::AsMut<#proxy_struct<'p>> for #proxy_name<'p> { fn as_mut(&mut self) -> &mut #proxy_struct<'p> { - &mut *self + self.inner_mut() } } @@ -876,7 +867,7 @@ fn gen_proxy_signal( #(#other_attrs)* pub #usage fn #receiver_with_args_name(&self, args: &[(u8, &str)]) -> #zbus::Result<#stream_name<'static>> { - self.receive_signal_with_args(#signal_name, args)#wait.map(#stream_name) + self.0.receive_signal_with_args(#signal_name, args)#wait.map(#stream_name) } } }; @@ -885,7 +876,7 @@ fn gen_proxy_signal( #(#other_attrs)* pub #usage fn #receiver_name(&self) -> #zbus::Result<#stream_name<'static>> { - self.receive_signal(#signal_name)#wait.map(#stream_name) + self.0.receive_signal(#signal_name)#wait.map(#stream_name) } #receive_signal_with_args @@ -1088,20 +1079,6 @@ fn gen_proxy_signal( } } - impl<'a> std::ops::Deref for #stream_name<'a> { - type Target = #zbus::#signal_type<'a>; - - fn deref(&self) -> &Self::Target { - &self.0 - } - } - - impl ::std::ops::DerefMut for #stream_name<'_> { - fn deref_mut(&mut self) -> &mut Self::Target { - &mut self.0 - } - } - #stream_impl #args_struct_decl