11use std:: fmt;
22use std:: fmt:: { Debug , Display , Formatter , Write } ;
33
4- use crate :: { QueryString , QUERY } ;
4+ use crate :: QUERY ;
55use percent_encoding:: utf8_percent_encode;
66
77/// A type alias for the [`WrappedQueryString`] root.
@@ -30,7 +30,7 @@ pub type QueryStringSimple = WrappedQueryString<RootMarker, EmptyValue>;
3030/// ```
3131pub struct WrappedQueryString < B , T >
3232where
33- B : ConditionalDisplay + Identifyable ,
33+ B : ConditionalDisplay + Identifiable ,
3434 T : Display ,
3535{
3636 base : BaseOption < B > ,
3939
4040impl Default for QueryStringSimple {
4141 fn default ( ) -> Self {
42- QueryString :: simple ( )
42+ QueryStringSimple :: new ( )
4343 }
4444}
4545
@@ -73,7 +73,7 @@ pub struct EmptyValue(());
7373
7474impl < B , T > WrappedQueryString < B , T >
7575where
76- B : ConditionalDisplay + Identifyable ,
76+ B : ConditionalDisplay + Identifiable ,
7777 T : Display ,
7878{
7979 /// Creates a new, empty query string builder.
@@ -173,36 +173,42 @@ where
173173 }
174174}
175175
176- pub trait Identifyable {
176+ pub trait Identifiable {
177177 fn is_root ( & self ) -> bool ;
178178 fn is_empty ( & self ) -> bool ;
179179 fn len ( & self ) -> usize ;
180180}
181181
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 {
183187 fn is_root ( & self ) -> bool {
184- true
188+ unreachable ! ( )
185189 }
186190
187191 fn is_empty ( & self ) -> bool {
188- true
192+ unreachable ! ( )
189193 }
190194
191195 fn len ( & self ) -> usize {
192- 0
196+ unreachable ! ( )
193197 }
194198}
195199
196- pub trait ConditionalDisplay {
197- fn cond_fmt ( & self , should_display : bool , f : & mut Formatter < ' _ > ) -> Result < usize , fmt:: Error > ;
198- }
199-
200200impl ConditionalDisplay for RootMarker {
201201 fn cond_fmt ( & self , _should_display : bool , _f : & mut Formatter < ' _ > ) -> Result < usize , fmt:: Error > {
202202 unreachable ! ( )
203203 }
204204}
205205
206+ impl Display for RootMarker {
207+ fn fmt ( & self , _f : & mut Formatter < ' _ > ) -> fmt:: Result {
208+ unreachable ! ( )
209+ }
210+ }
211+
206212impl < B > ConditionalDisplay for BaseOption < B >
207213where
208214 B : ConditionalDisplay ,
@@ -223,7 +229,7 @@ where
223229
224230impl < B , T > ConditionalDisplay for WrappedQueryString < B , T >
225231where
226- B : ConditionalDisplay + Identifyable ,
232+ B : ConditionalDisplay + Identifiable ,
227233 T : Display ,
228234{
229235 fn cond_fmt ( & self , should_display : bool , f : & mut Formatter < ' _ > ) -> Result < usize , fmt:: Error > {
@@ -260,7 +266,7 @@ where
260266
261267impl < B > BaseOption < B >
262268where
263- B : Identifyable + ConditionalDisplay ,
269+ B : Identifiable + ConditionalDisplay ,
264270{
265271 fn is_empty ( & self ) -> bool {
266272 match self {
@@ -277,9 +283,9 @@ where
277283 }
278284}
279285
280- impl < B , T > Identifyable for WrappedQueryString < B , T >
286+ impl < B , T > Identifiable for WrappedQueryString < B , T >
281287where
282- B : ConditionalDisplay + Identifyable ,
288+ B : ConditionalDisplay + Identifiable ,
283289 T : Display ,
284290{
285291 fn is_root ( & self ) -> bool {
@@ -313,14 +319,8 @@ impl<T> KvpOption<T> {
313319 }
314320}
315321
316- impl Display for RootMarker {
317- fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
318- f. write_char ( '?' )
319- }
320- }
321-
322322impl Display for EmptyValue {
323- fn fmt ( & self , _f : & mut Formatter < ' _ > ) -> std :: fmt:: Result {
323+ fn fmt ( & self , _f : & mut Formatter < ' _ > ) -> fmt:: Result {
324324 Ok ( ( ) )
325325 }
326326}
@@ -363,7 +363,7 @@ where
363363
364364impl < B , T > Display for WrappedQueryString < B , T >
365365where
366- B : ConditionalDisplay + Identifyable ,
366+ B : ConditionalDisplay + Identifiable ,
367367 T : Display ,
368368{
369369 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> std:: fmt:: Result {
@@ -380,7 +380,7 @@ where
380380
381381impl < B , T > Debug for WrappedQueryString < B , T >
382382where
383- B : ConditionalDisplay + Identifyable ,
383+ B : ConditionalDisplay + Identifiable ,
384384 T : Display ,
385385{
386386 fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
@@ -426,7 +426,7 @@ mod tests {
426426 assert_eq ! ( qs. len( ) , 4 ) ;
427427
428428 assert_eq ! (
429- qs . to_string ( ) ,
429+ format! ( "{qs}" ) ,
430430 "?q=apple???&category=fruits%20and%20vegetables&tasty=true&weight=99.9"
431431 ) ;
432432 }
@@ -453,7 +453,7 @@ mod tests {
453453 assert_eq ! ( qs. len( ) , 2 ) ;
454454
455455 assert_eq ! (
456- qs . to_string ( ) ,
456+ format! ( "{qs:?}" ) ,
457457 "?q=%F0%9F%A5%A6&%F0%9F%8D%BD%EF%B8%8F=%F0%9F%8D%94%F0%9F%8D%95"
458458 ) ;
459459 }
0 commit comments