@@ -184,19 +184,19 @@ impl UListener for SubscriptionChangeListener {
184184}
185185
186186/// A [`Publisher`] that uses the uProtocol Transport Layer API for publishing events to topics.
187- pub struct SimplePublisher {
188- transport : Arc < dyn UTransport > ,
189- uri_provider : Arc < dyn LocalUriProvider > ,
187+ pub struct SimplePublisher < T , P > {
188+ transport : Arc < T > ,
189+ uri_provider : Arc < P > ,
190190}
191191
192- impl SimplePublisher {
192+ impl < T : UTransport , P : LocalUriProvider > SimplePublisher < T , P > {
193193 /// Creates a new client.
194194 ///
195195 /// # Arguments
196196 ///
197197 /// * `transport` - The transport to use for sending messages.
198198 /// * `uri_provider` - The service to use for creating the event messages' _sink_ address.
199- pub fn new ( transport : Arc < dyn UTransport > , uri_provider : Arc < dyn LocalUriProvider > ) -> Self {
199+ pub fn new ( transport : Arc < T > , uri_provider : Arc < P > ) -> Self {
200200 SimplePublisher {
201201 transport,
202202 uri_provider,
@@ -205,7 +205,7 @@ impl SimplePublisher {
205205}
206206
207207#[ async_trait]
208- impl Publisher for SimplePublisher {
208+ impl < T : UTransport , P : LocalUriProvider > Publisher for SimplePublisher < T , P > {
209209 async fn publish (
210210 & self ,
211211 resource_id : u16 ,
@@ -242,15 +242,16 @@ impl Publisher for SimplePublisher {
242242/// about the new subscription and a (client provided) subscription change handler is registered with the
243243/// listener. When a subscription change notification arrives from the USubscription service, the corresponding
244244/// handler is being looked up and invoked.
245- pub struct InMemorySubscriber {
246- transport : Arc < dyn UTransport > ,
247- _uri_provider : Arc < dyn LocalUriProvider > ,
248- usubscription : Arc < dyn USubscription > ,
249- notifier : Arc < dyn Notifier > ,
245+ pub struct InMemorySubscriber < T , S , N > {
246+ transport : Arc < T > ,
247+ usubscription : Arc < S > ,
248+ notifier : Arc < N > ,
250249 subscription_change_listener : Arc < SubscriptionChangeListener > ,
251250}
252251
253- impl InMemorySubscriber {
252+ impl < T : UTransport + ' static , P : LocalUriProvider + ' static >
253+ InMemorySubscriber < T , RpcClientUSubscription , SimpleNotifier < T , P > >
254+ {
254255 /// Creates a new Subscriber for a given transport.
255256 ///
256257 /// The subscriber keeps track of subscription change handlers in memory only.
@@ -260,35 +261,32 @@ impl InMemorySubscriber {
260261 /// # Errors
261262 ///
262263 /// Returns an error if the Notifier cannot register a listener for notifications from the USubscription service.
263- pub async fn new (
264- transport : Arc < dyn UTransport > ,
265- uri_provider : Arc < dyn LocalUriProvider > ,
266- ) -> Result < Self , RegistrationError > {
264+ pub async fn new ( transport : Arc < T > , uri_provider : Arc < P > ) -> Result < Self , RegistrationError > {
267265 let rpc_client = InMemoryRpcClient :: new ( transport. clone ( ) , uri_provider. clone ( ) )
268266 . await
269267 . map ( Arc :: new) ?;
270268 let usubscription_client = Arc :: new ( RpcClientUSubscription :: new ( rpc_client) ) ;
271269 let notifier = Arc :: new ( SimpleNotifier :: new ( transport. clone ( ) , uri_provider. clone ( ) ) ) ;
272- Self :: for_clients ( transport, uri_provider , usubscription_client, notifier) . await
270+ Self :: for_clients ( transport, usubscription_client, notifier) . await
273271 }
272+ }
274273
274+ impl < T : UTransport , S : USubscription , N : Notifier > InMemorySubscriber < T , S , N > {
275275 /// Creates a new Subscriber for given clients.
276276 ///
277277 /// # Arguments
278278 ///
279279 /// * `transport` - The transport to use for registering the event listeners for subscribed topics.
280- /// * `uri-provider` - The service to use for creating topic addresses.
281280 /// * `usubscription` - The client to use for interacting with the (local) USubscription service.
282281 /// * `notifier` - The client to use for registering the listener for subscription updates from USubscription.
283282 ///
284283 /// # Errors
285284 ///
286285 /// Returns an error if the Notifier cannot register a listener for notifications from the USubscription service.
287286 pub async fn for_clients (
288- transport : Arc < dyn UTransport > ,
289- uri_provider : Arc < dyn LocalUriProvider > ,
290- usubscription : Arc < dyn USubscription > ,
291- notifier : Arc < dyn Notifier > ,
287+ transport : Arc < T > ,
288+ usubscription : Arc < S > ,
289+ notifier : Arc < N > ,
292290 ) -> Result < Self , RegistrationError > {
293291 // register a generic listener for subscription updates
294292 // whenever a uE later tries to subscribe to a topic, it can provide an optional callback for
@@ -304,7 +302,6 @@ impl InMemorySubscriber {
304302 . await ?;
305303 Ok ( InMemorySubscriber {
306304 transport,
307- _uri_provider : uri_provider,
308305 usubscription,
309306 notifier,
310307 subscription_change_listener,
@@ -400,7 +397,7 @@ impl InMemorySubscriber {
400397}
401398
402399#[ async_trait]
403- impl Subscriber for InMemorySubscriber {
400+ impl < T : UTransport , U : USubscription , N : Notifier > Subscriber for InMemorySubscriber < T , U , N > {
404401 async fn subscribe (
405402 & self ,
406403 topic_filter : & UUri ,
@@ -459,11 +456,11 @@ mod tests {
459456 StaticUriProvider , UAttributes , UCode , UMessageType , UPriority , UStatus , UUri , UUID ,
460457 } ;
461458
462- fn new_uri_provider ( ) -> Arc < dyn LocalUriProvider > {
459+ fn new_uri_provider ( ) -> Arc < StaticUriProvider > {
463460 Arc :: new ( StaticUriProvider :: new ( "" , 0x0005 , 0x02 ) )
464461 }
465462
466- fn succeeding_notifier ( ) -> Arc < dyn Notifier > {
463+ fn succeeding_notifier ( ) -> Arc < MockNotifier > {
467464 let mut notifier = MockNotifier :: new ( ) ;
468465 notifier
469466 . expect_start_listening ( )
@@ -586,7 +583,6 @@ mod tests {
586583 // WHEN trying to create a Subscriber for this Notifier
587584 let creation_attempt = InMemorySubscriber :: for_clients (
588585 Arc :: new ( MockTransport :: new ( ) ) ,
589- new_uri_provider ( ) ,
590586 Arc :: new ( MockUSubscription :: new ( ) ) ,
591587 Arc :: new ( notifier) ,
592588 )
@@ -612,7 +608,6 @@ mod tests {
612608
613609 let subscriber = InMemorySubscriber {
614610 transport : Arc :: new ( MockTransport :: new ( ) ) ,
615- _uri_provider : new_uri_provider ( ) ,
616611 usubscription : Arc :: new ( MockUSubscription :: new ( ) ) ,
617612 notifier : Arc :: new ( notifier) ,
618613 subscription_change_listener,
@@ -682,7 +677,6 @@ mod tests {
682677 // and a Subscriber using that USubscription client
683678 let subscriber = InMemorySubscriber :: for_clients (
684679 Arc :: new ( transport) ,
685- new_uri_provider ( ) ,
686680 Arc :: new ( usubscription_client) ,
687681 succeeding_notifier ( ) ,
688682 )
@@ -752,7 +746,6 @@ mod tests {
752746 // and a Subscriber using that USubscription client, Notifier and transport
753747 let subscriber = InMemorySubscriber :: for_clients (
754748 Arc :: new ( transport) ,
755- new_uri_provider ( ) ,
756749 Arc :: new ( usubscription_client) ,
757750 succeeding_notifier ( ) ,
758751 )
@@ -834,7 +827,6 @@ mod tests {
834827 // and a Subscriber using that USubscription client, Notifier and transport
835828 let subscriber = InMemorySubscriber :: for_clients (
836829 Arc :: new ( transport) ,
837- new_uri_provider ( ) ,
838830 Arc :: new ( usubscription_client) ,
839831 succeeding_notifier ( ) ,
840832 )
@@ -891,7 +883,6 @@ mod tests {
891883 // and a Subscriber using that USubscription client, Notifier and transport
892884 let subscriber = InMemorySubscriber :: for_clients (
893885 Arc :: new ( transport) ,
894- new_uri_provider ( ) ,
895886 Arc :: new ( usubscription_client) ,
896887 succeeding_notifier ( ) ,
897888 )
@@ -928,7 +919,6 @@ mod tests {
928919 // and a Subscriber using that USubscription client, Notifier and transport
929920 let subscriber = InMemorySubscriber :: for_clients (
930921 Arc :: new ( transport) ,
931- new_uri_provider ( ) ,
932922 Arc :: new ( usubscription_client) ,
933923 succeeding_notifier ( ) ,
934924 )
@@ -975,7 +965,6 @@ mod tests {
975965 // and a Subscriber using that USubscription client, Notifier and transport
976966 let subscriber = InMemorySubscriber :: for_clients (
977967 Arc :: new ( transport) ,
978- new_uri_provider ( ) ,
979968 Arc :: new ( usubscription_client) ,
980969 succeeding_notifier ( ) ,
981970 )
@@ -1031,7 +1020,6 @@ mod tests {
10311020 // and a Subscriber using that USubscription client, Notifier and transport
10321021 let subscriber = InMemorySubscriber :: for_clients (
10331022 Arc :: new ( transport) ,
1034- new_uri_provider ( ) ,
10351023 Arc :: new ( usubscription_client) ,
10361024 succeeding_notifier ( ) ,
10371025 )
0 commit comments