@@ -71,28 +71,31 @@ pub struct Tokens {
71
71
pub csrf_token : Option < String > ,
72
72
}
73
73
74
- #[ derive( Clone , Debug , Default ) ]
74
+ #[ derive( Clone , Debug , Default , PartialEq ) ]
75
75
pub struct Pagination {
76
- pub cursor : Option < String > ,
77
- pub limit : Option < usize > ,
78
- pub offset : Option < usize > ,
76
+ cursor : Option < String > ,
77
+ limit : Option < usize > ,
78
+ offset : Option < usize > ,
79
79
}
80
80
81
81
impl Pagination {
82
- pub fn with ( limit : impl Into < Option < usize > > , cursor : impl Into < Option < String > > ) -> Pagination {
83
- return Pagination {
84
- limit : limit. into ( ) ,
85
- cursor : cursor. into ( ) ,
86
- offset : None ,
87
- } ;
82
+ pub fn new ( ) -> Self {
83
+ return Self :: default ( ) ;
84
+ }
85
+
86
+ pub fn with_limit ( mut self , limit : impl Into < Option < usize > > ) -> Pagination {
87
+ self . limit = limit. into ( ) ;
88
+ return self ;
88
89
}
89
90
90
- pub fn with_limit ( limit : impl Into < Option < usize > > ) -> Pagination {
91
- return Pagination :: with ( limit, None ) ;
91
+ pub fn with_cursor ( mut self , cursor : impl Into < Option < String > > ) -> Pagination {
92
+ self . cursor = cursor. into ( ) ;
93
+ return self ;
92
94
}
93
95
94
- pub fn with_cursor ( cursor : impl Into < Option < String > > ) -> Pagination {
95
- return Pagination :: with ( None , cursor) ;
96
+ pub fn with_offset ( mut self , offset : impl Into < Option < usize > > ) -> Pagination {
97
+ self . offset = offset. into ( ) ;
98
+ return self ;
96
99
}
97
100
}
98
101
@@ -141,32 +144,43 @@ impl RecordId<'_> for i64 {
141
144
142
145
pub trait ReadArgumentsTrait < ' a > {
143
146
fn serialized_id ( self ) -> Cow < ' a , str > ;
144
- fn expand ( & self ) -> Option < & ' a [ & ' a str ] > ;
147
+ fn expand ( & self ) -> Option < & Vec < & ' a str > > ;
145
148
}
146
149
147
150
impl < ' a , T : RecordId < ' a > > ReadArgumentsTrait < ' a > for T {
148
151
fn serialized_id ( self ) -> Cow < ' a , str > {
149
152
return self . serialized_id ( ) ;
150
153
}
151
154
152
- fn expand ( & self ) -> Option < & ' a [ & ' a str ] > {
155
+ fn expand ( & self ) -> Option < & Vec < & ' a str > > {
153
156
return None ;
154
157
}
155
158
}
156
159
157
- #[ derive( Debug , Default ) ]
160
+ #[ derive( Clone , Debug , PartialEq ) ]
158
161
pub struct ReadArguments < ' a , T : RecordId < ' a > > {
159
- pub id : T ,
160
- pub expand : Option < & ' a [ & ' a str ] > ,
162
+ id : T ,
163
+ expand : Option < Vec < & ' a str > > ,
164
+ }
165
+
166
+ impl < ' a , T : RecordId < ' a > > ReadArguments < ' a , T > {
167
+ pub fn new ( id : T ) -> Self {
168
+ return Self { id, expand : None } ;
169
+ }
170
+
171
+ pub fn with_expand ( mut self , expand : impl AsRef < [ & ' a str ] > ) -> Self {
172
+ self . expand = Some ( expand. as_ref ( ) . to_vec ( ) ) ;
173
+ return self ;
174
+ }
161
175
}
162
176
163
177
impl < ' a , T : RecordId < ' a > > ReadArgumentsTrait < ' a > for ReadArguments < ' a , T > {
164
178
fn serialized_id ( self ) -> Cow < ' a , str > {
165
179
return self . id . serialized_id ( ) ;
166
180
}
167
181
168
- fn expand ( & self ) -> Option < & ' a [ & ' a str ] > {
169
- return self . expand ;
182
+ fn expand ( & self ) -> Option < & Vec < & ' a str > > {
183
+ return self . expand . as_ref ( ) ;
170
184
}
171
185
}
172
186
@@ -236,13 +250,44 @@ pub struct RecordApi {
236
250
name : String ,
237
251
}
238
252
239
- #[ derive( Default ) ]
253
+ #[ derive( Clone , Debug , Default , PartialEq ) ]
240
254
pub struct ListArguments < ' a > {
241
- pub pagination : Pagination ,
242
- pub order : Option < & ' a [ & ' a str ] > ,
243
- pub filters : Option < & ' a [ & ' a str ] > ,
244
- pub expand : Option < & ' a [ & ' a str ] > ,
245
- pub count : bool ,
255
+ pagination : Pagination ,
256
+ order : Option < Vec < & ' a str > > ,
257
+ filters : Option < Vec < & ' a str > > ,
258
+ expand : Option < Vec < & ' a str > > ,
259
+ count : bool ,
260
+ }
261
+
262
+ impl < ' a > ListArguments < ' a > {
263
+ pub fn new ( ) -> Self {
264
+ return ListArguments :: default ( ) ;
265
+ }
266
+
267
+ pub fn with_pagination ( mut self , pagination : Pagination ) -> Self {
268
+ self . pagination = pagination;
269
+ return self ;
270
+ }
271
+
272
+ pub fn with_order ( mut self , order : impl AsRef < [ & ' a str ] > ) -> Self {
273
+ self . order = Some ( order. as_ref ( ) . to_vec ( ) ) ;
274
+ return self ;
275
+ }
276
+
277
+ pub fn with_filters ( mut self , filters : impl AsRef < [ & ' a str ] > ) -> Self {
278
+ self . filters = Some ( filters. as_ref ( ) . to_vec ( ) ) ;
279
+ return self ;
280
+ }
281
+
282
+ pub fn with_expand ( mut self , expand : impl AsRef < [ & ' a str ] > ) -> Self {
283
+ self . expand = Some ( expand. as_ref ( ) . to_vec ( ) ) ;
284
+ return self ;
285
+ }
286
+
287
+ pub fn with_count ( mut self , count : bool ) -> Self {
288
+ self . count = count;
289
+ return self ;
290
+ }
246
291
}
247
292
248
293
impl RecordApi {
@@ -266,13 +311,13 @@ impl RecordApi {
266
311
267
312
if let Some ( order) = args. order {
268
313
if !order. is_empty ( ) {
269
- params. push ( ( Cow :: Borrowed ( "order" ) , Cow :: Owned ( to_list ( order) ) ) ) ;
314
+ params. push ( ( Cow :: Borrowed ( "order" ) , Cow :: Owned ( to_list ( & order) ) ) ) ;
270
315
}
271
316
}
272
317
273
318
if let Some ( expand) = args. expand {
274
319
if !expand. is_empty ( ) {
275
- params. push ( ( Cow :: Borrowed ( "expand" ) , Cow :: Owned ( to_list ( expand) ) ) ) ;
320
+ params. push ( ( Cow :: Borrowed ( "expand" ) , Cow :: Owned ( to_list ( & expand) ) ) ) ;
276
321
}
277
322
}
278
323
0 commit comments