diff --git a/zbus/src/blocking/connection/mod.rs b/zbus/src/blocking/connection/mod.rs index 66a7524c4..f43f7e759 100644 --- a/zbus/src/blocking/connection/mod.rs +++ b/zbus/src/blocking/connection/mod.rs @@ -3,7 +3,7 @@ use enumflags2::BitFlags; use event_listener::EventListener; use static_assertions::assert_impl_all; -use std::{io, ops::Deref, sync::Arc}; +use std::{io, ops::Deref}; use zbus_names::{BusName, ErrorName, InterfaceName, MemberName, OwnedUniqueName, WellKnownName}; use zvariant::ObjectPath; @@ -84,7 +84,7 @@ impl Connection { iface: Option, method_name: M, body: &B, - ) -> Result> + ) -> Result where D: TryInto>, P: TryInto>, diff --git a/zbus/src/blocking/message_iterator.rs b/zbus/src/blocking/message_iterator.rs index 928c0d43f..288dc66a4 100644 --- a/zbus/src/blocking/message_iterator.rs +++ b/zbus/src/blocking/message_iterator.rs @@ -1,6 +1,5 @@ use futures_util::StreamExt; use static_assertions::assert_impl_all; -use std::sync::Arc; use crate::{ blocking::Connection, message::Message, utils::block_on, MatchRule, OwnedMatchRule, Result, @@ -112,7 +111,7 @@ impl MessageIterator { } impl Iterator for MessageIterator { - type Item = Result>; + type Item = Result; fn next(&mut self) -> Option { block_on(self.azync.as_mut().expect("Inner stream is `None`").next()) diff --git a/zbus/src/blocking/proxy/mod.rs b/zbus/src/blocking/proxy/mod.rs index c6ada5f58..e1f7f43a8 100644 --- a/zbus/src/blocking/proxy/mod.rs +++ b/zbus/src/blocking/proxy/mod.rs @@ -3,7 +3,7 @@ use enumflags2::BitFlags; use futures_util::StreamExt; use static_assertions::assert_impl_all; -use std::{ops::Deref, sync::Arc}; +use std::ops::Deref; use zbus_names::{BusName, InterfaceName, MemberName, UniqueName}; use zvariant::{ObjectPath, OwnedValue, Value}; @@ -207,7 +207,7 @@ impl<'a> Proxy<'a> { /// allocation/copying, by deserializing the reply to an unowned type). /// /// [`call`]: struct.Proxy.html#method.call - pub fn call_method<'m, M, B>(&self, method_name: M, body: &B) -> Result> + pub fn call_method<'m, M, B>(&self, method_name: M, body: &B) -> Result where M: TryInto>, M::Error: Into, @@ -393,7 +393,7 @@ impl<'a> SignalIterator<'a> { assert_impl_all!(SignalIterator<'_>: Send, Sync, Unpin); impl std::iter::Iterator for SignalIterator<'_> { - type Item = Arc; + type Item = Message; fn next(&mut self) -> Option { block_on(self.0.as_mut().expect("`SignalStream` is `None`").next()) diff --git a/zbus/src/connection/mod.rs b/zbus/src/connection/mod.rs index 88d022240..892d1f72a 100644 --- a/zbus/src/connection/mod.rs +++ b/zbus/src/connection/mod.rs @@ -66,8 +66,8 @@ pub(crate) struct ConnectionInner { #[allow(unused)] socket_reader_task: OnceCell>, - pub(crate) msg_receiver: InactiveReceiver>>, - pub(crate) method_return_receiver: InactiveReceiver>>, + pub(crate) msg_receiver: InactiveReceiver>, + pub(crate) method_return_receiver: InactiveReceiver>, msg_senders: Arc, MsgBroadcaster>>>, subscriptions: Mutex, @@ -76,9 +76,9 @@ pub(crate) struct ConnectionInner { object_server_dispatch_task: OnceCell>, } -type Subscriptions = HashMap>>)>; +type Subscriptions = HashMap>)>; -pub(crate) type MsgBroadcaster = Broadcaster>>; +pub(crate) type MsgBroadcaster = Broadcaster>; /// A D-Bus connection. /// @@ -206,7 +206,7 @@ pub(crate) struct PendingMethodCall { } impl Future for PendingMethodCall { - type Output = Result>; + type Output = Result; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { self.poll_before(cx, None).map(|ret| { @@ -220,7 +220,7 @@ impl Future for PendingMethodCall { } impl OrderedFuture for PendingMethodCall { - type Output = Result>; + type Output = Result; type Ordering = zbus::message::Sequence; fn poll_before( @@ -311,7 +311,7 @@ impl Connection { interface: Option, method_name: M, body: &B, - ) -> Result> + ) -> Result where D: TryInto>, P: TryInto>, @@ -1028,7 +1028,7 @@ impl Connection { &self, rule: OwnedMatchRule, max_queued: Option, - ) -> Result>>> { + ) -> Result>> { use std::collections::hash_map::Entry; if self.inner.msg_senders.lock().await.is_empty() { diff --git a/zbus/src/connection/socket_reader.rs b/zbus/src/connection/socket_reader.rs index 92fc6dab0..9b1713e7d 100644 --- a/zbus/src/connection/socket_reader.rs +++ b/zbus/src/connection/socket_reader.rs @@ -94,7 +94,7 @@ impl SocketReader { } #[instrument] - async fn read_socket(&mut self) -> crate::Result> { + async fn read_socket(&mut self) -> crate::Result { self.activity_event.notify(usize::MAX); let mut bytes = self .already_received_bytes @@ -185,6 +185,5 @@ impl SocketReader { fds, seq, ) - .map(Arc::new) } } diff --git a/zbus/src/error.rs b/zbus/src/error.rs index 3ab0b3ea1..620fce1d8 100644 --- a/zbus/src/error.rs +++ b/zbus/src/error.rs @@ -38,7 +38,7 @@ pub enum Error { /// A D-Bus method error reply. // According to the spec, there can be all kinds of details in D-Bus errors but nobody adds // anything more than a string description. - MethodError(OwnedErrorName, Option, Arc), + MethodError(OwnedErrorName, Option, Message), /// A required field is missing in the message headers. MissingField, /// Invalid D-Bus GUID. @@ -226,12 +226,6 @@ impl From for Error { // For messages that are D-Bus error returns impl From for Error { fn from(message: Message) -> Error { - Self::from(Arc::new(message)) - } -} - -impl From> for Error { - fn from(message: Arc) -> Error { // FIXME: Instead of checking this, we should have Method as trait and specific types for // each message type. let header = message.header(); diff --git a/zbus/src/message_stream.rs b/zbus/src/message_stream.rs index 7c112f5d2..aac999850 100644 --- a/zbus/src/message_stream.rs +++ b/zbus/src/message_stream.rs @@ -165,7 +165,7 @@ impl MessageStream { } pub(crate) fn for_subscription_channel( - msg_receiver: ActiveReceiver>>, + msg_receiver: ActiveReceiver>, rule: Option, conn: &Connection, ) -> Self { @@ -182,7 +182,7 @@ impl MessageStream { } impl stream::Stream for MessageStream { - type Item = Result>; + type Item = Result; fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { let this = self.get_mut(); @@ -192,7 +192,7 @@ impl stream::Stream for MessageStream { } impl OrderedStream for MessageStream { - type Data = Result>; + type Data = Result; type Ordering = Sequence; fn poll_next_before( @@ -274,7 +274,7 @@ impl From<&MessageStream> for Connection { #[derive(Clone, Debug)] struct Inner { conn_inner: Arc, - msg_receiver: ActiveReceiver>>, + msg_receiver: ActiveReceiver>, match_rule: Option, } diff --git a/zbus/src/proxy/mod.rs b/zbus/src/proxy/mod.rs index 70c8cea90..a929a7898 100644 --- a/zbus/src/proxy/mod.rs +++ b/zbus/src/proxy/mod.rs @@ -801,7 +801,7 @@ impl<'a> Proxy<'a> { /// allocation/copying, by deserializing the reply to an unowned type). /// /// [`call`]: struct.Proxy.html#method.call - pub async fn call_method<'m, M, B>(&self, method_name: M, body: &B) -> Result> + pub async fn call_method<'m, M, B>(&self, method_name: M, body: &B) -> Result where M: TryInto>, M::Error: Into, @@ -1231,7 +1231,7 @@ impl<'a> SignalStream<'a> { }) } - fn filter(&mut self, msg: &Arc) -> Result { + fn filter(&mut self, msg: &Message) -> Result { let header = msg.header(); let sender = header.sender(); if sender == self.src_unique_name.as_ref() { @@ -1251,7 +1251,7 @@ impl<'a> SignalStream<'a> { assert_impl_all!(SignalStream<'_>: Send, Sync, Unpin); impl<'a> stream::Stream for SignalStream<'a> { - type Item = Arc; + type Item = Message; fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { OrderedStream::poll_next_before(self, cx, None).map(|res| res.into_data()) @@ -1259,7 +1259,7 @@ impl<'a> stream::Stream for SignalStream<'a> { } impl<'a> OrderedStream for SignalStream<'a> { - type Data = Arc; + type Data = Message; type Ordering = Sequence; fn poll_next_before( diff --git a/zbus_macros/src/proxy.rs b/zbus_macros/src/proxy.rs index 35acdb90b..0ec851631 100644 --- a/zbus_macros/src/proxy.rs +++ b/zbus_macros/src/proxy.rs @@ -933,7 +933,7 @@ fn gen_proxy_signal( quote! { #[doc = #args_struct_gen_doc] #[derive(Debug, Clone)] - pub struct #signal_name_ident(::std::sync::Arc<#zbus::message::Message>); + pub struct #signal_name_ident(#zbus::message::Message); impl ::std::ops::Deref for #signal_name_ident { type Target = #zbus::message::Message; @@ -943,12 +943,6 @@ fn gen_proxy_signal( } } - impl ::std::convert::AsRef<::std::sync::Arc<#zbus::message::Message>> for #signal_name_ident { - fn as_ref(&self) -> &::std::sync::Arc<#zbus::message::Message> { - &self.0 - } - } - impl ::std::convert::AsRef<#zbus::message::Message> for #signal_name_ident { fn as_ref(&self) -> &#zbus::message::Message { &self.0 @@ -961,7 +955,7 @@ fn gen_proxy_signal( #[doc = " from a [::zbus::message::Message]."] pub fn from_message(msg: M) -> ::std::option::Option where - M: ::std::convert::Into<::std::sync::Arc<#zbus::message::Message>>, + M: ::std::convert::Into<#zbus::message::Message>, { let msg = msg.into(); let hdr = msg.header(); diff --git a/zbus_macros/tests/tests.rs b/zbus_macros/tests/tests.rs index f6595ded4..502030e11 100644 --- a/zbus_macros/tests/tests.rs +++ b/zbus_macros/tests/tests.rs @@ -257,7 +257,6 @@ fn test_interface() { mod signal_from_message { use super::*; - use std::sync::Arc; use zbus::message::Message; #[dbus_proxy( @@ -275,16 +274,14 @@ mod signal_from_message { #[test] fn signal_u8() { - let message = Arc::new( - Message::signal( - "/org/freedesktop/zbus_macros/test", - "org.freedesktop.zbus_macros.Test", - "SignalU8", - ) - .expect("Failed to create signal message builder") - .build(&(1u8,)) - .expect("Failed to build signal message"), - ); + let message = Message::signal( + "/org/freedesktop/zbus_macros/test", + "org.freedesktop.zbus_macros.Test", + "SignalU8", + ) + .expect("Failed to create signal message builder") + .build(&(1u8,)) + .expect("Failed to build signal message"); assert!( SignalU8::from_message(message.clone()).is_some(), @@ -298,16 +295,14 @@ mod signal_from_message { #[test] fn signal_string() { - let message = Arc::new( - Message::signal( - "/org/freedesktop/zbus_macros/test", - "org.freedesktop.zbus_macros.Test", - "SignalString", - ) - .expect("Failed to create signal message builder") - .build(&(String::from("test"),)) - .expect("Failed to build signal message"), - ); + let message = Message::signal( + "/org/freedesktop/zbus_macros/test", + "org.freedesktop.zbus_macros.Test", + "SignalString", + ) + .expect("Failed to create signal message builder") + .build(&(String::from("test"),)) + .expect("Failed to build signal message"); assert!( SignalString::from_message(message.clone()).is_some(), @@ -321,16 +316,14 @@ mod signal_from_message { #[test] fn wrong_data() { - let message = Arc::new( - Message::signal( - "/org/freedesktop/zbus_macros/test", - "org.freedesktop.zbus_macros.Test", - "SignalU8", - ) - .expect("Failed to create signal message builder") - .build(&(String::from("test"),)) - .expect("Failed to build signal message"), - ); + let message = Message::signal( + "/org/freedesktop/zbus_macros/test", + "org.freedesktop.zbus_macros.Test", + "SignalU8", + ) + .expect("Failed to create signal message builder") + .build(&(String::from("test"),)) + .expect("Failed to build signal message"); let signal = SignalU8::from_message(message).expect("Message is a SignalU8"); signal