11use routefinder:: { Captures , Router as MethodRouter } ;
22use std:: collections:: HashMap ;
3- use std:: sync:: Arc ;
43
5- use crate :: endpoint:: DynEndpoint ;
6- use crate :: { Request , Response , StatusCode } ;
4+ use crate :: { Next , Request , Response , StatusCode } ;
75
86/// The routing table used by `Server`
97///
108/// Internally, we have a separate state machine per http method; indexing
119/// by the method first allows the table itself to be more efficient.
1210#[ allow( missing_debug_implementations) ]
1311pub ( crate ) struct Router {
14- method_map : HashMap < http_types:: Method , MethodRouter < Arc < DynEndpoint > > > ,
15- all_method_router : MethodRouter < Arc < DynEndpoint > > ,
12+ method_map : HashMap < http_types:: Method , MethodRouter < Next > > ,
13+ all_method_router : MethodRouter < Next > ,
1614}
1715
1816impl std:: fmt:: Debug for Router {
@@ -26,7 +24,7 @@ impl std::fmt::Debug for Router {
2624
2725/// The result of routing a URL
2826pub ( crate ) struct Selection {
29- pub ( crate ) endpoint : Arc < DynEndpoint > ,
27+ pub ( crate ) next : Next ,
3028 pub ( crate ) params : Captures < ' static , ' static > ,
3129}
3230
@@ -38,15 +36,15 @@ impl Router {
3836 }
3937 }
4038
41- pub ( crate ) fn add ( & mut self , path : & str , method : http_types:: Method , ep : Arc < DynEndpoint > ) {
39+ pub ( crate ) fn add ( & mut self , path : & str , method : http_types:: Method , ep : Next ) {
4240 self . method_map
4341 . entry ( method)
4442 . or_insert_with ( MethodRouter :: new)
4543 . add ( path, ep)
4644 . unwrap ( )
4745 }
4846
49- pub ( crate ) fn add_all ( & mut self , path : & str , ep : Arc < DynEndpoint > ) {
47+ pub ( crate ) fn add_all ( & mut self , path : & str , ep : Next ) {
5048 self . all_method_router . add ( path, ep) . unwrap ( )
5149 }
5250
@@ -57,12 +55,12 @@ impl Router {
5755 . and_then ( |r| r. best_match ( path) )
5856 {
5957 Selection {
60- endpoint : m. handler ( ) . to_owned ( ) ,
58+ next : m. handler ( ) . clone ( ) ,
6159 params : m. captures ( ) . into_owned ( ) ,
6260 }
6361 } else if let Some ( m) = self . all_method_router . best_match ( path) {
6462 Selection {
65- endpoint : m. handler ( ) . to_owned ( ) ,
63+ next : m. handler ( ) . clone ( ) ,
6664 params : m. captures ( ) . into_owned ( ) ,
6765 }
6866 } else if method == http_types:: Method :: Head {
@@ -79,12 +77,12 @@ impl Router {
7977 // If this `path` can be handled by a callback registered with a different HTTP method
8078 // should return 405 Method Not Allowed
8179 Selection {
82- endpoint : Arc :: new ( method_not_allowed) ,
80+ next : Next :: from_endpoint ( method_not_allowed) ,
8381 params : Captures :: default ( ) ,
8482 }
8583 } else {
8684 Selection {
87- endpoint : Arc :: new ( not_found_endpoint) ,
85+ next : Next :: from_endpoint ( not_found_endpoint) ,
8886 params : Captures :: default ( ) ,
8987 }
9088 }
0 commit comments