1
- use async_trait:: async_trait;
2
1
use rand:: prelude:: * ;
3
2
use std:: fmt:: Display ;
3
+ use std:: future:: Future ;
4
4
use std:: ops:: ControlFlow ;
5
5
use std:: sync:: Arc ;
6
6
use thiserror:: Error ;
@@ -75,18 +75,17 @@ impl Display for MultiError {
75
75
}
76
76
77
77
/// How to connect to a `Transport`
78
- #[ async_trait]
79
78
trait ConnectionHandler {
80
79
type R : RequestHandler + Send + Sync ;
81
80
82
- async fn connect (
81
+ fn connect (
83
82
& self ,
84
83
client_id : Arc < str > ,
85
84
tls_config : TlsConfig ,
86
85
socks5_proxy : Option < String > ,
87
86
sasl_config : Option < SaslConfig > ,
88
87
max_message_size : usize ,
89
- ) -> Result < Arc < Self :: R > > ;
88
+ ) -> impl Future < Output = Result < Arc < Self :: R > > > + Send ;
90
89
}
91
90
92
91
/// Defines the possible request modes of metadata retrieval.
@@ -138,7 +137,6 @@ impl BrokerRepresentation {
138
137
}
139
138
}
140
139
141
- #[ async_trait]
142
140
impl ConnectionHandler for BrokerRepresentation {
143
141
type R = MessengerTransport ;
144
142
@@ -373,15 +371,13 @@ impl std::fmt::Debug for BrokerConnector {
373
371
}
374
372
}
375
373
376
- #[ async_trait]
377
374
trait RequestHandler {
378
- async fn metadata_request (
375
+ fn metadata_request (
379
376
& self ,
380
377
request_params : & MetadataRequest ,
381
- ) -> Result < MetadataResponse , RequestError > ;
378
+ ) -> impl Future < Output = Result < MetadataResponse , RequestError > > + Send ;
382
379
}
383
380
384
- #[ async_trait]
385
381
impl RequestHandler for MessengerTransport {
386
382
async fn metadata_request (
387
383
& self ,
@@ -415,18 +411,22 @@ impl BrokerCacheGeneration {
415
411
}
416
412
}
417
413
418
- #[ async_trait]
419
414
pub trait BrokerCache : Send + Sync {
420
415
type R : Send + Sync ;
421
416
type E : std:: error:: Error + Send + Sync ;
422
417
423
- async fn get ( & self ) -> Result < ( Arc < Self :: R > , BrokerCacheGeneration ) , Self :: E > ;
418
+ fn get (
419
+ & self ,
420
+ ) -> impl Future < Output = Result < ( Arc < Self :: R > , BrokerCacheGeneration ) , Self :: E > > + Send ;
424
421
425
- async fn invalidate ( & self , reason : & ' static str , gen : BrokerCacheGeneration ) ;
422
+ fn invalidate (
423
+ & self ,
424
+ reason : & ' static str ,
425
+ gen : BrokerCacheGeneration ,
426
+ ) -> impl Future < Output = ( ) > + Send ;
426
427
}
427
428
428
429
/// BrokerConnector caches an arbitrary broker that can successfully connect.
429
- #[ async_trait]
430
430
impl BrokerCache for & BrokerConnector {
431
431
type R = MessengerTransport ;
432
432
type E = Error ;
@@ -602,7 +602,6 @@ mod tests {
602
602
}
603
603
}
604
604
605
- #[ async_trait]
606
605
impl RequestHandler for FakeBroker {
607
606
async fn metadata_request (
608
607
& self ,
@@ -617,7 +616,6 @@ mod tests {
617
616
invalidate : Box < dyn Fn ( ) + Send + Sync > ,
618
617
}
619
618
620
- #[ async_trait]
621
619
impl BrokerCache for FakeBrokerCache {
622
620
type R = FakeBroker ;
623
621
type E = Error ;
@@ -794,7 +792,6 @@ mod tests {
794
792
#[ derive( Debug , PartialEq ) ]
795
793
struct FakeConn ;
796
794
797
- #[ async_trait]
798
795
impl RequestHandler for FakeConn {
799
796
async fn metadata_request (
800
797
& self ,
@@ -804,7 +801,6 @@ mod tests {
804
801
}
805
802
}
806
803
807
- #[ async_trait]
808
804
impl ConnectionHandler for FakeBrokerRepresentation {
809
805
type R = FakeConn ;
810
806
0 commit comments