2
2
3
3
use chrono:: { DateTime , NaiveDate , Utc } ;
4
4
use serde_derive:: * ;
5
- use std:: collections:: HashMap ;
5
+ use std:: { collections:: HashMap , fmt } ;
6
6
7
- /// Used to specify the sort behaviour of the `Client::crates()` method .
7
+ /// A list of errors returned by the API .
8
8
#[ derive( Deserialize , Debug , Clone , PartialEq , Eq ) ]
9
9
pub struct ApiErrors {
10
10
/// Individual errors.
11
11
pub errors : Vec < ApiError > ,
12
12
}
13
13
14
- /// Used to specify the sort behaviour of the `Client::crates()` method .
14
+ /// An error returned by the API .
15
15
#[ derive( Deserialize , Debug , Clone , PartialEq , Eq ) ]
16
16
pub struct ApiError {
17
17
/// Error message.
18
18
pub detail : Option < String > ,
19
19
}
20
20
21
- impl std :: fmt:: Display for ApiError {
22
- fn fmt ( & self , f : & mut std :: fmt:: Formatter < ' _ > ) -> std :: fmt:: Result {
21
+ impl fmt:: Display for ApiError {
22
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
23
23
write ! (
24
24
f,
25
25
"{}" ,
@@ -77,6 +77,8 @@ pub struct CratesQuery {
77
77
pub ( crate ) category : Option < String > ,
78
78
/// Search query string.
79
79
pub ( crate ) search : Option < String > ,
80
+ /// List of crate ids.
81
+ pub ( crate ) ids : Option < Vec < String > > ,
80
82
}
81
83
82
84
impl CratesQuery {
@@ -93,6 +95,11 @@ impl CratesQuery {
93
95
if let Some ( cat) = & self . category {
94
96
q. append_pair ( "category" , cat) ;
95
97
}
98
+ if let Some ( ids) = & self . ids {
99
+ for id in ids {
100
+ q. append_pair ( "ids[]" , id) ;
101
+ }
102
+ }
96
103
}
97
104
}
98
105
@@ -161,6 +168,16 @@ impl CratesQuery {
161
168
pub fn set_search ( & mut self , search : Option < String > ) {
162
169
self . search = search;
163
170
}
171
+
172
+ /// Get a reference to the crate query's ids.
173
+ pub fn ids ( & self ) -> Option < & Vec < String > > {
174
+ self . ids . as_ref ( )
175
+ }
176
+
177
+ /// Set the crate query's ids.
178
+ pub fn set_ids ( & mut self , ids : Option < Vec < String > > ) {
179
+ self . ids = ids;
180
+ }
164
181
}
165
182
166
183
impl Default for CratesQuery {
@@ -172,6 +189,7 @@ impl Default for CratesQuery {
172
189
user_id : None ,
173
190
category : None ,
174
191
search : None ,
192
+ ids : None ,
175
193
}
176
194
}
177
195
}
@@ -235,6 +253,13 @@ impl CratesQueryBuilder {
235
253
self
236
254
}
237
255
256
+ /// List of crate ids.
257
+ #[ must_use]
258
+ pub fn ids ( mut self , ids : Vec < String > ) -> Self {
259
+ self . query . ids = Some ( ids) ;
260
+ self
261
+ }
262
+
238
263
/// Finalize the builder into a usable [`CratesQuery`].
239
264
#[ must_use]
240
265
pub fn build ( self ) -> CratesQuery {
0 commit comments