@@ -5,7 +5,7 @@ use crate::route::handler_match::{Match, RouteMatched};
55use  crate :: Method ; 
66use  hyper:: StatusCode ; 
77use  std:: collections:: HashMap ; 
8- use  std:: fmt:: Display ; 
8+ use  std:: fmt; 
99use  std:: sync:: Arc ; 
1010
1111pub ( crate )  mod  handler_append; 
@@ -18,18 +18,31 @@ pub struct Route {
1818    pub  children :  Vec < Route > , 
1919    pub  middlewares :  Vec < Arc < dyn  Handler > > , 
2020    special_match :  bool , 
21+     create_path :  String , 
2122} 
2223
23- impl  Display  for  Route  { 
24-     fn  fmt ( & self ,  f :  & mut  std:: fmt:: Formatter < ' _ > )  -> std:: fmt:: Result  { 
25-         let  mut  path = self . path . clone ( ) ; 
26-         if  path. is_empty ( )  { 
27-             path = "/" . to_string ( ) ; 
24+ impl  fmt:: Debug  for  Route  { 
25+     fn  fmt ( & self ,  f :  & mut  fmt:: Formatter < ' _ > )  -> fmt:: Result  { 
26+         fn  get_route_str ( pre_fix :  String ,  route :  & Route )  -> String  { 
27+             let  space_pre_fix = format ! ( "    {}" ,  pre_fix) ; 
28+             let  mut  route_strs:  Vec < String >  = route
29+                 . children 
30+                 . iter ( ) 
31+                 . filter ( |r| !r. handler . is_empty ( )  || !r. children . is_empty ( ) ) 
32+                 . map ( |r| get_route_str ( space_pre_fix. clone ( ) ,  r) ) 
33+                 . collect ( ) ; 
34+             if  !route. handler . is_empty ( )  || !route. children . is_empty ( )  { 
35+                 let  methods:  Vec < String >  = route. handler . keys ( ) . map ( |m| m. to_string ( ) ) . collect ( ) ; 
36+                 let  methods_str = if  methods. is_empty ( )  { 
37+                     "" . to_string ( ) 
38+                 }  else  { 
39+                     format ! ( "({})" ,  methods. join( "," ) ) 
40+                 } ; 
41+                 route_strs. insert ( 0 ,  format ! ( "{}{}{}" ,  pre_fix,  route. path,  methods_str) ) ; 
42+             } 
43+             route_strs. join ( "\n " ) 
2844        } 
29-         for  route in  & self . children  { 
30-             write ! ( f,  "{}" ,  route) ?; 
31-         } 
32-         write ! ( f,  "{}" ,  path) 
45+         write ! ( f,  "{}" ,  get_route_str( "" . to_string( ) ,  self ) ) 
3346    } 
3447} 
3548
@@ -44,6 +57,7 @@ impl Route {
4457            children :  Vec :: new ( ) , 
4558            middlewares :  Vec :: new ( ) , 
4659            special_match :  first_path. starts_with ( '<' )  && first_path. ends_with ( '>' ) , 
60+             create_path :  path. to_string ( ) , 
4761        } ; 
4862        if  last_path. is_empty ( )  { 
4963            route
@@ -62,12 +76,12 @@ pub struct Routes {
6276    pub  children :  Vec < Route > , 
6377} 
6478
65- impl  Display  for  Routes  { 
66-     fn  fmt ( & self ,  f :  & mut  std :: fmt:: Formatter < ' _ > )  -> std :: fmt:: Result  { 
79+ impl  fmt :: Debug  for  Routes  { 
80+     fn  fmt ( & self ,  f :  & mut  fmt:: Formatter < ' _ > )  -> fmt:: Result  { 
6781        let  path = self 
6882            . children 
6983            . iter ( ) 
70-             . map ( |route| route . to_string ( ) ) 
84+             . map ( |route| format ! ( "{:?}" ,  route ) ) 
7185            . collect :: < Vec < String > > ( ) 
7286            . join ( "\n " ) ; 
7387        write ! ( f,  "{}" ,  path) 
0 commit comments