@@ -6,6 +6,8 @@ use serde::de::DeserializeOwned;
6
6
7
7
use std:: collections:: VecDeque ;
8
8
9
+ use web_time:: Duration ;
10
+
9
11
use super :: Error ;
10
12
use crate :: error:: JsonDecodeError ;
11
13
use crate :: types:: * ;
@@ -15,8 +17,8 @@ use crate::util::*;
15
17
#[ derive( Clone ) ]
16
18
pub struct Client {
17
19
client : HttpClient ,
18
- rate_limit : std :: time :: Duration ,
19
- last_request_time : std:: sync:: Arc < tokio:: sync:: Mutex < Option < tokio :: time :: Instant > > > ,
20
+ rate_limit : Duration ,
21
+ last_request_time : std:: sync:: Arc < tokio:: sync:: Mutex < Option < web_time :: Instant > > > ,
20
22
base_url : Url ,
21
23
}
22
24
@@ -113,17 +115,18 @@ impl Client {
113
115
/// Example user agent: `"my_bot (my_bot.com/info)"` or `"my_bot (help@my_bot.com)"`.
114
116
///
115
117
/// ```rust
118
+ /// # use web_time::Duration;
116
119
/// # fn f() -> Result<(), Box<dyn std::error::Error>> {
117
120
/// let client = crates_io_api::AsyncClient::new(
118
121
/// "my_bot (help@my_bot.com)",
119
- /// std::time:: Duration::from_millis(1000),
122
+ /// Duration::from_millis(1000),
120
123
/// ).unwrap();
121
124
/// # Ok(())
122
125
/// # }
123
126
/// ```
124
127
pub fn new (
125
128
user_agent : & str ,
126
- rate_limit : std :: time :: Duration ,
129
+ rate_limit : Duration ,
127
130
) -> Result < Self , reqwest:: header:: InvalidHeaderValue > {
128
131
let mut headers = header:: HeaderMap :: new ( ) ;
129
132
headers. insert (
@@ -147,7 +150,7 @@ impl Client {
147
150
/// At most one request will be executed in the specified duration.
148
151
/// The guidelines suggest 1 per second or less.
149
152
/// (Only one request is executed concurrenly, even if the given Duration is 0).
150
- pub fn with_http_client ( client : HttpClient , rate_limit : std :: time :: Duration ) -> Self {
153
+ pub fn with_http_client ( client : HttpClient , rate_limit : Duration ) -> Self {
151
154
let limiter = std:: sync:: Arc :: new ( tokio:: sync:: Mutex :: new ( None ) ) ;
152
155
153
156
Self {
@@ -167,7 +170,7 @@ impl Client {
167
170
}
168
171
}
169
172
170
- let time = tokio :: time :: Instant :: now ( ) ;
173
+ let time = web_time :: Instant :: now ( ) ;
171
174
let res = self . client . get ( url. clone ( ) ) . send ( ) . await ?;
172
175
173
176
if !res. status ( ) . is_success ( ) {
@@ -399,7 +402,7 @@ mod test {
399
402
fn build_test_client ( ) -> Client {
400
403
Client :: new (
401
404
"crates-io-api-continuous-integration (github.com/theduke/crates-io-api)" ,
402
- std :: time :: Duration :: from_millis ( 1000 ) ,
405
+ web_time :: Duration :: from_millis ( 1000 ) ,
403
406
)
404
407
. unwrap ( )
405
408
}
0 commit comments