@@ -19,7 +19,7 @@ pub(crate) enum Trait {
19
19
}
20
20
21
21
impl Trait {
22
- fn via_marker_type ( & self ) -> Option < Type > {
22
+ fn via_marker_type ( self ) -> Option < Type > {
23
23
match self {
24
24
Self :: FromRequest => Some ( parse_quote ! ( M ) ) ,
25
25
Self :: FromRequestParts => None ,
@@ -132,17 +132,17 @@ pub(crate) fn expand(item: syn::Item, tr: Trait) -> syn::Result<TokenStream> {
132
132
133
133
let trait_impl = match ( via. map ( second) , rejection. map ( second) ) {
134
134
( Some ( via) , rejection) => impl_struct_by_extracting_all_at_once (
135
- ident,
135
+ & ident,
136
136
fields,
137
- via,
138
- rejection,
139
- generic_ident,
137
+ & via,
138
+ rejection. as_ref ( ) ,
139
+ generic_ident. as_ref ( ) ,
140
140
& state,
141
141
tr,
142
142
) ?,
143
143
( None , rejection) => {
144
144
error_on_generic_ident ( generic_ident, tr) ?;
145
- impl_struct_by_extracting_each_field ( ident, fields, rejection, & state, tr) ?
145
+ impl_struct_by_extracting_each_field ( & ident, & fields, rejection, & state, tr) ?
146
146
}
147
147
} ;
148
148
@@ -206,11 +206,11 @@ pub(crate) fn expand(item: syn::Item, tr: Trait) -> syn::Result<TokenStream> {
206
206
207
207
match ( via. map ( second) , rejection) {
208
208
( Some ( via) , rejection) => impl_enum_by_extracting_all_at_once (
209
- ident,
209
+ & ident,
210
210
variants,
211
- via,
212
- rejection. map ( second) ,
213
- state,
211
+ & via,
212
+ rejection. map ( second) . as_ref ( ) ,
213
+ & state,
214
214
tr,
215
215
) ,
216
216
( None , Some ( ( rejection_kw, _) ) ) => Err ( syn:: Error :: new_spanned (
@@ -328,8 +328,8 @@ fn error_on_generic_ident(generic_ident: Option<Ident>, tr: Trait) -> syn::Resul
328
328
}
329
329
330
330
fn impl_struct_by_extracting_each_field (
331
- ident : syn:: Ident ,
332
- fields : syn:: Fields ,
331
+ ident : & syn:: Ident ,
332
+ fields : & syn:: Fields ,
333
333
rejection : Option < syn:: Path > ,
334
334
state : & State ,
335
335
tr : Trait ,
@@ -339,7 +339,7 @@ fn impl_struct_by_extracting_each_field(
339
339
:: std:: unimplemented!( )
340
340
}
341
341
} else {
342
- let extract_fields = extract_fields ( & fields, & rejection, tr) ?;
342
+ let extract_fields = extract_fields ( fields, rejection. as_ref ( ) , tr) ?;
343
343
quote ! {
344
344
:: std:: result:: Result :: Ok ( Self {
345
345
#( #extract_fields) *
@@ -349,7 +349,7 @@ fn impl_struct_by_extracting_each_field(
349
349
350
350
let rejection_ident = if let Some ( rejection) = rejection {
351
351
quote ! ( #rejection)
352
- } else if has_no_fields ( & fields) {
352
+ } else if has_no_fields ( fields) {
353
353
quote ! ( :: std:: convert:: Infallible )
354
354
} else {
355
355
quote ! ( :: axum:: response:: Response )
@@ -411,7 +411,7 @@ fn has_no_fields(fields: &syn::Fields) -> bool {
411
411
412
412
fn extract_fields (
413
413
fields : & syn:: Fields ,
414
- rejection : & Option < syn:: Path > ,
414
+ rejection : Option < & syn:: Path > ,
415
415
tr : Trait ,
416
416
) -> syn:: Result < Vec < TokenStream > > {
417
417
fn member ( field : & syn:: Field , index : usize ) -> TokenStream {
@@ -426,7 +426,7 @@ fn extract_fields(
426
426
}
427
427
}
428
428
429
- fn into_inner ( via : & Option < ( attr:: kw:: via , syn:: Path ) > , ty_span : Span ) -> TokenStream {
429
+ fn into_inner ( via : Option < & ( attr:: kw:: via , syn:: Path ) > , ty_span : Span ) -> TokenStream {
430
430
if let Some ( ( _, path) ) = via {
431
431
let span = path. span ( ) ;
432
432
quote_spanned ! { span=>
@@ -440,7 +440,7 @@ fn extract_fields(
440
440
}
441
441
442
442
fn into_outer (
443
- via : & Option < ( attr:: kw:: via , syn:: Path ) > ,
443
+ via : Option < & ( attr:: kw:: via , syn:: Path ) > ,
444
444
ty_span : Span ,
445
445
field_ty : & Type ,
446
446
) -> TokenStream {
@@ -472,10 +472,10 @@ fn extract_fields(
472
472
473
473
let member = member ( field, index) ;
474
474
let ty_span = field. ty . span ( ) ;
475
- let into_inner = into_inner ( & via, ty_span) ;
475
+ let into_inner = into_inner ( via. as_ref ( ) , ty_span) ;
476
476
477
477
if peel_option ( & field. ty ) . is_some ( ) {
478
- let field_ty = into_outer ( & via, ty_span, peel_option ( & field. ty ) . unwrap ( ) ) ;
478
+ let field_ty = into_outer ( via. as_ref ( ) , ty_span, peel_option ( & field. ty ) . unwrap ( ) ) ;
479
479
let tokens = match tr {
480
480
Trait :: FromRequest => {
481
481
quote_spanned ! { ty_span=>
@@ -510,7 +510,7 @@ fn extract_fields(
510
510
} ;
511
511
Ok ( tokens)
512
512
} else if peel_result_ok ( & field. ty ) . is_some ( ) {
513
- let field_ty = into_outer ( & via, ty_span, peel_result_ok ( & field. ty ) . unwrap ( ) ) ;
513
+ let field_ty = into_outer ( via. as_ref ( ) , ty_span, peel_result_ok ( & field. ty ) . unwrap ( ) ) ;
514
514
let tokens = match tr {
515
515
Trait :: FromRequest => {
516
516
quote_spanned ! { ty_span=>
@@ -543,7 +543,7 @@ fn extract_fields(
543
543
} ;
544
544
Ok ( tokens)
545
545
} else {
546
- let field_ty = into_outer ( & via, ty_span, & field. ty ) ;
546
+ let field_ty = into_outer ( via. as_ref ( ) , ty_span, & field. ty ) ;
547
547
let map_err = if let Some ( rejection) = rejection {
548
548
quote ! { <#rejection as :: std:: convert:: From <_>>:: from }
549
549
} else {
@@ -593,10 +593,10 @@ fn extract_fields(
593
593
594
594
let member = member ( field, fields. len ( ) - 1 ) ;
595
595
let ty_span = field. ty . span ( ) ;
596
- let into_inner = into_inner ( & via, ty_span) ;
596
+ let into_inner = into_inner ( via. as_ref ( ) , ty_span) ;
597
597
598
598
let item = if peel_option ( & field. ty ) . is_some ( ) {
599
- let field_ty = into_outer ( & via, ty_span, peel_option ( & field. ty ) . unwrap ( ) ) ;
599
+ let field_ty = into_outer ( via. as_ref ( ) , ty_span, peel_option ( & field. ty ) . unwrap ( ) ) ;
600
600
quote_spanned ! { ty_span=>
601
601
#member: {
602
602
<#field_ty as :: axum:: extract:: FromRequest <_, _>>:: from_request( req, state)
@@ -606,7 +606,7 @@ fn extract_fields(
606
606
} ,
607
607
}
608
608
} else if peel_result_ok ( & field. ty ) . is_some ( ) {
609
- let field_ty = into_outer ( & via, ty_span, peel_result_ok ( & field. ty ) . unwrap ( ) ) ;
609
+ let field_ty = into_outer ( via. as_ref ( ) , ty_span, peel_result_ok ( & field. ty ) . unwrap ( ) ) ;
610
610
quote_spanned ! { ty_span=>
611
611
#member: {
612
612
<#field_ty as :: axum:: extract:: FromRequest <_, _>>:: from_request( req, state)
@@ -615,7 +615,7 @@ fn extract_fields(
615
615
} ,
616
616
}
617
617
} else {
618
- let field_ty = into_outer ( & via, ty_span, & field. ty ) ;
618
+ let field_ty = into_outer ( via. as_ref ( ) , ty_span, & field. ty ) ;
619
619
let map_err = if let Some ( rejection) = rejection {
620
620
quote ! { <#rejection as :: std:: convert:: From <_>>:: from }
621
621
} else {
@@ -697,11 +697,11 @@ fn peel_result_ok(ty: &syn::Type) -> Option<&syn::Type> {
697
697
}
698
698
699
699
fn impl_struct_by_extracting_all_at_once (
700
- ident : syn:: Ident ,
700
+ ident : & syn:: Ident ,
701
701
fields : syn:: Fields ,
702
- via_path : syn:: Path ,
703
- rejection : Option < syn:: Path > ,
704
- generic_ident : Option < Ident > ,
702
+ via_path : & syn:: Path ,
703
+ rejection : Option < & syn:: Path > ,
704
+ generic_ident : Option < & Ident > ,
705
705
state : & State ,
706
706
tr : Trait ,
707
707
) -> syn:: Result < TokenStream > {
@@ -750,7 +750,7 @@ fn impl_struct_by_extracting_all_at_once(
750
750
// - `State`, not other extractors
751
751
//
752
752
// honestly not sure why but the tests all pass
753
- let via_marker_type = if path_ident_is_state ( & via_path) {
753
+ let via_marker_type = if path_ident_is_state ( via_path) {
754
754
tr. via_marker_type ( )
755
755
} else {
756
756
None
@@ -868,11 +868,11 @@ fn impl_struct_by_extracting_all_at_once(
868
868
}
869
869
870
870
fn impl_enum_by_extracting_all_at_once (
871
- ident : syn:: Ident ,
871
+ ident : & syn:: Ident ,
872
872
variants : Punctuated < syn:: Variant , Token ! [ , ] > ,
873
- path : syn:: Path ,
874
- rejection : Option < syn:: Path > ,
875
- state : State ,
873
+ path : & syn:: Path ,
874
+ rejection : Option < & syn:: Path > ,
875
+ state : & State ,
876
876
tr : Trait ,
877
877
) -> syn:: Result < TokenStream > {
878
878
for variant in variants {
0 commit comments