1
1
use std:: fmt;
2
2
use std:: fmt:: { Debug , Display , Formatter , Write } ;
3
3
4
- use crate :: { QueryString , QUERY } ;
4
+ use crate :: QUERY ;
5
5
use percent_encoding:: utf8_percent_encode;
6
6
7
7
/// A type alias for the [`WrappedQueryString`] root.
@@ -30,7 +30,7 @@ pub type QueryStringSimple = WrappedQueryString<RootMarker, EmptyValue>;
30
30
/// ```
31
31
pub struct WrappedQueryString < B , T >
32
32
where
33
- B : ConditionalDisplay + Identifyable ,
33
+ B : ConditionalDisplay + Identifiable ,
34
34
T : Display ,
35
35
{
36
36
base : BaseOption < B > ,
39
39
40
40
impl Default for QueryStringSimple {
41
41
fn default ( ) -> Self {
42
- QueryString :: simple ( )
42
+ QueryStringSimple :: new ( )
43
43
}
44
44
}
45
45
@@ -73,7 +73,7 @@ pub struct EmptyValue(());
73
73
74
74
impl < B , T > WrappedQueryString < B , T >
75
75
where
76
- B : ConditionalDisplay + Identifyable ,
76
+ B : ConditionalDisplay + Identifiable ,
77
77
T : Display ,
78
78
{
79
79
/// Creates a new, empty query string builder.
@@ -173,36 +173,42 @@ where
173
173
}
174
174
}
175
175
176
- pub trait Identifyable {
176
+ pub trait Identifiable {
177
177
fn is_root ( & self ) -> bool ;
178
178
fn is_empty ( & self ) -> bool ;
179
179
fn len ( & self ) -> usize ;
180
180
}
181
181
182
- impl Identifyable for RootMarker {
182
+ pub trait ConditionalDisplay {
183
+ fn cond_fmt ( & self , should_display : bool , f : & mut Formatter < ' _ > ) -> Result < usize , fmt:: Error > ;
184
+ }
185
+
186
+ impl Identifiable for RootMarker {
183
187
fn is_root ( & self ) -> bool {
184
- true
188
+ unreachable ! ( )
185
189
}
186
190
187
191
fn is_empty ( & self ) -> bool {
188
- true
192
+ unreachable ! ( )
189
193
}
190
194
191
195
fn len ( & self ) -> usize {
192
- 0
196
+ unreachable ! ( )
193
197
}
194
198
}
195
199
196
- pub trait ConditionalDisplay {
197
- fn cond_fmt ( & self , should_display : bool , f : & mut Formatter < ' _ > ) -> Result < usize , fmt:: Error > ;
198
- }
199
-
200
200
impl ConditionalDisplay for RootMarker {
201
201
fn cond_fmt ( & self , _should_display : bool , _f : & mut Formatter < ' _ > ) -> Result < usize , fmt:: Error > {
202
202
unreachable ! ( )
203
203
}
204
204
}
205
205
206
+ impl Display for RootMarker {
207
+ fn fmt ( & self , _f : & mut Formatter < ' _ > ) -> fmt:: Result {
208
+ unreachable ! ( )
209
+ }
210
+ }
211
+
206
212
impl < B > ConditionalDisplay for BaseOption < B >
207
213
where
208
214
B : ConditionalDisplay ,
@@ -223,7 +229,7 @@ where
223
229
224
230
impl < B , T > ConditionalDisplay for WrappedQueryString < B , T >
225
231
where
226
- B : ConditionalDisplay + Identifyable ,
232
+ B : ConditionalDisplay + Identifiable ,
227
233
T : Display ,
228
234
{
229
235
fn cond_fmt ( & self , should_display : bool , f : & mut Formatter < ' _ > ) -> Result < usize , fmt:: Error > {
@@ -260,7 +266,7 @@ where
260
266
261
267
impl < B > BaseOption < B >
262
268
where
263
- B : Identifyable + ConditionalDisplay ,
269
+ B : Identifiable + ConditionalDisplay ,
264
270
{
265
271
fn is_empty ( & self ) -> bool {
266
272
match self {
@@ -277,9 +283,9 @@ where
277
283
}
278
284
}
279
285
280
- impl < B , T > Identifyable for WrappedQueryString < B , T >
286
+ impl < B , T > Identifiable for WrappedQueryString < B , T >
281
287
where
282
- B : ConditionalDisplay + Identifyable ,
288
+ B : ConditionalDisplay + Identifiable ,
283
289
T : Display ,
284
290
{
285
291
fn is_root ( & self ) -> bool {
@@ -313,14 +319,8 @@ impl<T> KvpOption<T> {
313
319
}
314
320
}
315
321
316
- impl Display for RootMarker {
317
- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
318
- f. write_char ( '?' )
319
- }
320
- }
321
-
322
322
impl Display for EmptyValue {
323
- fn fmt ( & self , _f : & mut Formatter < ' _ > ) -> std :: fmt:: Result {
323
+ fn fmt ( & self , _f : & mut Formatter < ' _ > ) -> fmt:: Result {
324
324
Ok ( ( ) )
325
325
}
326
326
}
@@ -363,7 +363,7 @@ where
363
363
364
364
impl < B , T > Display for WrappedQueryString < B , T >
365
365
where
366
- B : ConditionalDisplay + Identifyable ,
366
+ B : ConditionalDisplay + Identifiable ,
367
367
T : Display ,
368
368
{
369
369
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
@@ -380,7 +380,7 @@ where
380
380
381
381
impl < B , T > Debug for WrappedQueryString < B , T >
382
382
where
383
- B : ConditionalDisplay + Identifyable ,
383
+ B : ConditionalDisplay + Identifiable ,
384
384
T : Display ,
385
385
{
386
386
fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
@@ -426,7 +426,7 @@ mod tests {
426
426
assert_eq ! ( qs. len( ) , 4 ) ;
427
427
428
428
assert_eq ! (
429
- qs . to_string ( ) ,
429
+ format! ( "{qs}" ) ,
430
430
"?q=apple???&category=fruits%20and%20vegetables&tasty=true&weight=99.9"
431
431
) ;
432
432
}
0 commit comments