File tree Expand file tree Collapse file tree 3 files changed +11
-5
lines changed Expand file tree Collapse file tree 3 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -668,12 +668,12 @@ where
668668 }
669669 }
670670
671- fn call_with_state ( & mut self , req : Request , state : S ) -> RouteFuture < E > {
671+ fn call_with_state ( self , req : Request , state : S ) -> RouteFuture < E > {
672672 match self {
673- Fallback :: Default ( route) | Fallback :: Service ( route) => route. oneshot_inner ( req) ,
673+ Fallback :: Default ( route) | Fallback :: Service ( route) => route. oneshot_inner_owned ( req) ,
674674 Fallback :: BoxedHandler ( handler) => {
675- let mut route = handler. clone ( ) . into_route ( state) ;
676- route. oneshot_inner ( req)
675+ let route = handler. clone ( ) . into_route ( state) ;
676+ route. oneshot_inner_owned ( req)
677677 }
678678 }
679679 }
Original file line number Diff line number Diff line change @@ -47,6 +47,12 @@ impl<E> Route<E> {
4747 RouteFuture :: new ( method, self . 0 . clone ( ) . oneshot ( req) )
4848 }
4949
50+ /// Variant of [`Route::oneshot_inner`] that takes ownership of the route to avoid cloning.
51+ pub ( crate ) fn oneshot_inner_owned ( self , req : Request ) -> RouteFuture < E > {
52+ let method = req. method ( ) . clone ( ) ;
53+ RouteFuture :: new ( method, self . 0 . oneshot ( req) )
54+ }
55+
5056 pub ( crate ) fn layer < L , NewError > ( self , layer : L ) -> Route < NewError >
5157 where
5258 L : Layer < Route < E > > + Clone + Send + ' static ,
Original file line number Diff line number Diff line change @@ -344,5 +344,5 @@ async fn state_isnt_cloned_too_much_with_fallback() {
344344
345345 client. get ( "/does-not-exist" ) . await ;
346346
347- assert_eq ! ( state. count( ) , 4 ) ;
347+ assert_eq ! ( state. count( ) , 3 ) ;
348348}
You can’t perform that action at this time.
0 commit comments