@@ -77,44 +77,42 @@ impl FangsList {
7777 Self ( Vec :: new ( ) )
7878 }
7979
80- fn add ( & mut self , id : ID , fangs : Arc < dyn Fangs > ) {
80+ fn add_inner ( & mut self , id : ID , fangs : Arc < dyn Fangs > ) {
8181 if self . 0 . iter ( ) . all ( |( _id, _) | * _id != id) {
8282 self . 0 . push ( ( id, fangs) ) ;
8383 }
8484 }
85- pub ( super ) fn append ( & mut self , another : Self ) {
86- for ( id , fangs ) in another . 0 . into_iter ( ) {
87- self . add ( id, fangs)
85+ fn add_outer ( & mut self , id : ID , fangs : Arc < dyn Fangs > ) {
86+ if self . 0 . iter ( ) . all ( | ( _id , _ ) | * _id != id ) {
87+ self . 0 . insert ( 0 , ( id, fangs) ) ;
8888 }
8989 }
90-
91- /// yield from most inner fangs
92- fn into_iter ( self ) -> impl Iterator < Item = Arc < dyn Fangs > > {
93- self . 0 . into_iter ( ) . map ( | ( _ , fangs ) | fangs )
90+ pub ( super ) fn append_inner ( & mut self , another : Self ) {
91+ for ( id , fangs) in another . 0 . into_iter ( ) {
92+ self . add_inner ( id , fangs ) ;
93+ }
9494 }
9595
9696 pub ( super ) fn into_proc_with ( self , h : Handler ) -> IntoProcWith {
97- let mut iter = self . into_iter ( ) ;
98-
9997 #[ cfg( not( feature = "openapi" ) ) ]
100- match iter. next ( ) {
101- None => h. proc ,
102- Some ( most_inner) => {
103- iter. fold ( most_inner. build ( h. proc ) , |proc, fangs| fangs. build ( proc) )
104- }
98+ {
99+ self . 0
100+ . into_iter ( )
101+ . rfold ( h. proc , |proc, ( _, most_inner_fangs) | {
102+ most_inner_fangs. build ( proc)
103+ } )
105104 }
106105 #[ cfg( feature = "openapi" ) ]
107- match iter. next ( ) {
108- None => ( h. proc , h. openapi_operation ) ,
109- Some ( most_inner) => iter. fold (
110- (
111- most_inner. build ( h. proc ) ,
112- most_inner. openapi_map_operation ( h. openapi_operation ) ,
113- ) ,
114- |( proc, operation) , fangs| {
115- ( fangs. build ( proc) , fangs. openapi_map_operation ( operation) )
106+ {
107+ self . 0 . into_iter ( ) . rfold (
108+ ( h. proc , h. openapi_operation ) ,
109+ |( proc, op) , ( _, most_inner_fangs) | {
110+ (
111+ most_inner_fangs. build ( proc) ,
112+ most_inner_fangs. openapi_map_operation ( operation) ,
113+ )
116114 } ,
117- ) ,
115+ )
118116 }
119117 }
120118}
@@ -362,10 +360,6 @@ impl Node {
362360 }
363361 }
364362
365- fn append_fangs ( & mut self , fangs : FangsList ) {
366- self . fangses . append ( fangs) ;
367- }
368-
369363 fn set_handler ( & mut self , new_handler : Handler , allow_override : bool ) -> Result < ( ) , String > {
370364 if self . handler . is_some ( ) && !allow_override {
371365 return Err ( format ! ( "Conflicting handler registering" ) ) ;
@@ -414,7 +408,7 @@ impl Node {
414408 panic ! ( "Unexpectedly called `Node::merge_here` where `another_root` is not root node" )
415409 } ;
416410
417- self . append_fangs ( another_root_fangses) ;
411+ self . fangses . append_inner ( another_root_fangses) ;
418412
419413 if let Some ( h) = another_root_handler {
420414 self . set_handler ( h, allow_override_handler) ?;
@@ -432,10 +426,10 @@ impl Node {
432426 for child in & mut self . children {
433427 child. apply_fangs ( id, fangs. clone ( ) )
434428 }
435-
436429 // Add even when `self.handler.is_none()`. They are used later
437430 // for applying to `Handler::default_notfound`s in `finalize`.
438- self . fangses . add ( id, fangs) ;
431+ // This `fangses` must be added by `_outer` to *wrap* existing fangs.
432+ self . fangses . add_outer ( id, fangs) ;
439433 }
440434}
441435
0 commit comments