@@ -10,7 +10,7 @@ use std::{
1010 collections:: BTreeMap ,
1111 convert:: TryFrom ,
1212 error:: Error ,
13- fmt:: { self , Display , Formatter } ,
13+ fmt:: { self , Debug , Display , Formatter } ,
1414 time:: { SystemTime , SystemTimeError } ,
1515} ;
1616
@@ -70,35 +70,38 @@ pub trait Request {
7070 payload : & T ,
7171 ) -> Result < U , Self :: Error >
7272 where
73- T : Serialize + Send + Sync ,
74- U : DeserializeOwned + Send + Sync ;
73+ T : Serialize + Debug + Send + Sync ,
74+ U : DeserializeOwned + Debug + Send + Sync ;
7575}
7676
7777// -----------------------------------------------------------------------------
7878// RestClient trait
7979
8080#[ async_trait]
81- pub trait RestClient {
81+ pub trait RestClient
82+ where
83+ Self : Debug ,
84+ {
8285 type Error ;
8386
8487 async fn get < T > ( & self , endpoint : & str ) -> Result < T , Self :: Error >
8588 where
86- T : DeserializeOwned + Send + Sync ;
89+ T : DeserializeOwned + Debug + Send + Sync ;
8790
8891 async fn post < T , U > ( & self , endpoint : & str , payload : & T ) -> Result < U , Self :: Error >
8992 where
90- T : Serialize + Send + Sync ,
91- U : DeserializeOwned + Send + Sync ;
93+ T : Serialize + Debug + Send + Sync ,
94+ U : DeserializeOwned + Debug + Send + Sync ;
9295
9396 async fn put < T , U > ( & self , endpoint : & str , payload : & T ) -> Result < U , Self :: Error >
9497 where
95- T : Serialize + Send + Sync ,
96- U : DeserializeOwned + Send + Sync ;
98+ T : Serialize + Debug + Send + Sync ,
99+ U : DeserializeOwned + Debug + Send + Sync ;
97100
98101 async fn patch < T , U > ( & self , endpoint : & str , payload : & T ) -> Result < U , Self :: Error >
99102 where
100- T : Serialize + Send + Sync ,
101- U : DeserializeOwned + Send + Sync ;
103+ T : Serialize + Debug + Send + Sync ,
104+ U : DeserializeOwned + Debug + Send + Sync ;
102105
103106 async fn delete ( & self , endpoint : & str ) -> Result < ( ) , Self :: Error > ;
104107}
@@ -127,7 +130,10 @@ pub const OAUTH1_VERSION: &str = "oauth_version";
127130pub const OAUTH1_VERSION_1 : & str = "1.0" ;
128131pub const OAUTH1_TOKEN : & str = "oauth_token" ;
129132
130- pub trait OAuth1 {
133+ pub trait OAuth1
134+ where
135+ Self : Debug ,
136+ {
131137 type Error ;
132138
133139 // `params` returns OAuth1 parameters without the signature one
@@ -139,6 +145,7 @@ pub trait OAuth1 {
139145 // `signing_key` returns the key that is used to signed the signature
140146 fn signing_key ( & self ) -> String ;
141147
148+ #[ cfg_attr( feature = "trace" , tracing:: instrument) ]
142149 // `sign` returns OAuth1 formatted Authorization header value
143150 fn sign ( & self , method : & str , endpoint : & str ) -> Result < String , Self :: Error > {
144151 let signature = self . signature ( method, endpoint) ?;
@@ -171,7 +178,7 @@ pub struct ResponseError {
171178}
172179
173180impl Display for ResponseError {
174- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
181+ fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
175182 write ! (
176183 f,
177184 "got response {} {}, {}" ,
@@ -208,6 +215,7 @@ pub struct Signer {
208215impl OAuth1 for Signer {
209216 type Error = SignerError ;
210217
218+ #[ cfg_attr( feature = "trace" , tracing:: instrument) ]
211219 fn params ( & self ) -> BTreeMap < String , String > {
212220 let mut params = BTreeMap :: new ( ) ;
213221
@@ -226,6 +234,7 @@ impl OAuth1 for Signer {
226234 params
227235 }
228236
237+ #[ cfg_attr( feature = "trace" , tracing:: instrument) ]
229238 fn signing_key ( & self ) -> String {
230239 format ! (
231240 "{}&{}" ,
@@ -234,6 +243,7 @@ impl OAuth1 for Signer {
234243 )
235244 }
236245
246+ #[ cfg_attr( feature = "trace" , tracing:: instrument) ]
237247 fn signature ( & self , method : & str , endpoint : & str ) -> Result < String , Self :: Error > {
238248 let ( host, query) = match endpoint. find ( |c| '?' == c) {
239249 None => ( endpoint, "" ) ,
@@ -283,6 +293,7 @@ impl OAuth1 for Signer {
283293impl TryFrom < Credentials > for Signer {
284294 type Error = SignerError ;
285295
296+ #[ cfg_attr( feature = "trace" , tracing:: instrument) ]
286297 fn try_from ( credentials : Credentials ) -> Result < Self , Self :: Error > {
287298 let nonce = Uuid :: new_v4 ( ) . to_string ( ) ;
288299 let timestamp = SystemTime :: now ( )
@@ -334,15 +345,16 @@ pub struct Client {
334345impl Request for Client {
335346 type Error = ClientError ;
336347
348+ #[ cfg_attr( feature = "trace" , tracing:: instrument) ]
337349 async fn request < T , U > (
338350 & self ,
339351 method : & Method ,
340352 endpoint : & str ,
341353 payload : & T ,
342354 ) -> Result < U , Self :: Error >
343355 where
344- T : Serialize + Send + Sync ,
345- U : DeserializeOwned + Send + Sync ,
356+ T : Serialize + Debug + Send + Sync ,
357+ U : DeserializeOwned + Debug + Send + Sync ,
346358 {
347359 let buf = serde_json:: to_vec ( payload) . map_err ( ClientError :: Serialize ) ?;
348360 let mut builder = hyper:: Request :: builder ( ) ;
@@ -426,9 +438,10 @@ impl Request for Client {
426438impl RestClient for Client {
427439 type Error = ClientError ;
428440
441+ #[ cfg_attr( feature = "trace" , tracing:: instrument) ]
429442 async fn get < T > ( & self , endpoint : & str ) -> Result < T , Self :: Error >
430443 where
431- T : DeserializeOwned + Send + Sync ,
444+ T : DeserializeOwned + Debug + Send + Sync ,
432445 {
433446 let method = & Method :: GET ;
434447 let mut builder = hyper:: Request :: builder ( ) ;
@@ -506,30 +519,34 @@ impl RestClient for Client {
506519 Ok ( serde_json:: from_reader ( buf. reader ( ) ) . map_err ( ClientError :: Deserialize ) ?)
507520 }
508521
522+ #[ cfg_attr( feature = "trace" , tracing:: instrument) ]
509523 async fn post < T , U > ( & self , endpoint : & str , payload : & T ) -> Result < U , Self :: Error >
510524 where
511- T : Serialize + Send + Sync ,
512- U : DeserializeOwned + Send + Sync ,
525+ T : Serialize + Debug + Send + Sync ,
526+ U : DeserializeOwned + Debug + Send + Sync ,
513527 {
514528 self . request ( & Method :: POST , endpoint, payload) . await
515529 }
516530
531+ #[ cfg_attr( feature = "trace" , tracing:: instrument) ]
517532 async fn put < T , U > ( & self , endpoint : & str , payload : & T ) -> Result < U , Self :: Error >
518533 where
519- T : Serialize + Send + Sync ,
520- U : DeserializeOwned + Send + Sync ,
534+ T : Serialize + Debug + Send + Sync ,
535+ U : DeserializeOwned + Debug + Send + Sync ,
521536 {
522537 self . request ( & Method :: PUT , endpoint, payload) . await
523538 }
524539
540+ #[ cfg_attr( feature = "trace" , tracing:: instrument) ]
525541 async fn patch < T , U > ( & self , endpoint : & str , payload : & T ) -> Result < U , Self :: Error >
526542 where
527- T : Serialize + Send + Sync ,
528- U : DeserializeOwned + Send + Sync ,
543+ T : Serialize + Debug + Send + Sync ,
544+ U : DeserializeOwned + Debug + Send + Sync ,
529545 {
530546 self . request ( & Method :: PATCH , endpoint, payload) . await
531547 }
532548
549+ #[ cfg_attr( feature = "trace" , tracing:: instrument) ]
533550 async fn delete ( & self , endpoint : & str ) -> Result < ( ) , Self :: Error > {
534551 let method = & Method :: DELETE ;
535552 let mut builder = hyper:: Request :: builder ( ) ;
@@ -609,6 +626,7 @@ impl RestClient for Client {
609626}
610627
611628impl Default for Client {
629+ #[ cfg_attr( feature = "trace" , tracing:: instrument) ]
612630 fn default ( ) -> Self {
613631 let connector = HttpsConnector :: new ( ) ;
614632 let inner = hyper:: Client :: builder ( ) . build ( connector) ;
@@ -621,6 +639,7 @@ impl Default for Client {
621639}
622640
623641impl From < Credentials > for Client {
642+ #[ cfg_attr( feature = "trace" , tracing:: instrument) ]
624643 fn from ( credentials : Credentials ) -> Self {
625644 let mut client = Self :: default ( ) ;
626645 client. set_credentials ( Some ( credentials) ) ;
@@ -629,6 +648,7 @@ impl From<Credentials> for Client {
629648}
630649
631650impl Client {
651+ #[ cfg_attr( feature = "trace" , tracing:: instrument) ]
632652 pub fn set_credentials ( & mut self , credentials : Option < Credentials > ) {
633653 self . credentials = credentials;
634654 }
0 commit comments