mirror of
https://github.com/tokio-rs/axum.git
synced 2024-12-13 18:30:42 +01:00
revert trait_generics
This commit is contained in:
parent
d9f2035e7b
commit
133b8abb7b
1 changed files with 14 additions and 16 deletions
|
@ -6,7 +6,6 @@ use crate::{
|
||||||
use proc_macro2::{Span, TokenStream};
|
use proc_macro2::{Span, TokenStream};
|
||||||
use quote::{quote, quote_spanned, ToTokens};
|
use quote::{quote, quote_spanned, ToTokens};
|
||||||
use std::{collections::HashSet, fmt, iter};
|
use std::{collections::HashSet, fmt, iter};
|
||||||
use syn::token::Comma;
|
|
||||||
use syn::{
|
use syn::{
|
||||||
parse_quote, punctuated::Punctuated, spanned::Spanned, Fields, Ident, Path, Token, Type,
|
parse_quote, punctuated::Punctuated, spanned::Spanned, Fields, Ident, Path, Token, Type,
|
||||||
};
|
};
|
||||||
|
@ -340,16 +339,12 @@ fn impl_struct_by_extracting_each_field(
|
||||||
state: &State,
|
state: &State,
|
||||||
tr: Trait,
|
tr: Trait,
|
||||||
) -> syn::Result<TokenStream> {
|
) -> syn::Result<TokenStream> {
|
||||||
let trait_generics = state
|
|
||||||
.trait_generics()
|
|
||||||
.collect::<Punctuated<Type, Token![,]>>();
|
|
||||||
|
|
||||||
let trait_fn_body = match state {
|
let trait_fn_body = match state {
|
||||||
State::CannotInfer => quote! {
|
State::CannotInfer => quote! {
|
||||||
::std::unimplemented!()
|
::std::unimplemented!()
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
let extract_fields = extract_fields(&fields, &rejection, tr, &trait_generics)?;
|
let extract_fields = extract_fields(&fields, &rejection, tr)?;
|
||||||
quote! {
|
quote! {
|
||||||
::std::result::Result::Ok(Self {
|
::std::result::Result::Ok(Self {
|
||||||
#(#extract_fields)*
|
#(#extract_fields)*
|
||||||
|
@ -370,6 +365,10 @@ fn impl_struct_by_extracting_each_field(
|
||||||
.impl_generics()
|
.impl_generics()
|
||||||
.collect::<Punctuated<Type, Token![,]>>();
|
.collect::<Punctuated<Type, Token![,]>>();
|
||||||
|
|
||||||
|
let trait_generics = state
|
||||||
|
.trait_generics()
|
||||||
|
.collect::<Punctuated<Type, Token![,]>>();
|
||||||
|
|
||||||
let state_bounds = state.bounds();
|
let state_bounds = state.bounds();
|
||||||
|
|
||||||
Ok(match tr {
|
Ok(match tr {
|
||||||
|
@ -420,7 +419,6 @@ fn extract_fields(
|
||||||
fields: &syn::Fields,
|
fields: &syn::Fields,
|
||||||
rejection: &Option<syn::Path>,
|
rejection: &Option<syn::Path>,
|
||||||
tr: Trait,
|
tr: Trait,
|
||||||
trait_generics: &Punctuated<Type, Comma>,
|
|
||||||
) -> syn::Result<Vec<TokenStream>> {
|
) -> syn::Result<Vec<TokenStream>> {
|
||||||
fn member(field: &syn::Field, index: usize) -> TokenStream {
|
fn member(field: &syn::Field, index: usize) -> TokenStream {
|
||||||
match &field.ident {
|
match &field.ident {
|
||||||
|
@ -491,7 +489,7 @@ fn extract_fields(
|
||||||
#member: {
|
#member: {
|
||||||
let (mut parts, body) = req.into_parts();
|
let (mut parts, body) = req.into_parts();
|
||||||
let value =
|
let value =
|
||||||
<#field_ty as ::axum::extract::FromRequestParts<#trait_generics>>::from_request_parts(
|
<#field_ty as ::axum::extract::FromRequestParts<_>>::from_request_parts(
|
||||||
&mut parts,
|
&mut parts,
|
||||||
state,
|
state,
|
||||||
)
|
)
|
||||||
|
@ -506,7 +504,7 @@ fn extract_fields(
|
||||||
Trait::FromRequestParts => {
|
Trait::FromRequestParts => {
|
||||||
quote_spanned! {ty_span=>
|
quote_spanned! {ty_span=>
|
||||||
#member: {
|
#member: {
|
||||||
<#field_ty as ::axum::extract::FromRequestParts<#trait_generics>>::from_request_parts(
|
<#field_ty as ::axum::extract::FromRequestParts<_>>::from_request_parts(
|
||||||
parts,
|
parts,
|
||||||
state,
|
state,
|
||||||
)
|
)
|
||||||
|
@ -526,7 +524,7 @@ fn extract_fields(
|
||||||
#member: {
|
#member: {
|
||||||
let (mut parts, body) = req.into_parts();
|
let (mut parts, body) = req.into_parts();
|
||||||
let value =
|
let value =
|
||||||
<#field_ty as ::axum::extract::FromRequestParts<#trait_generics>>::from_request_parts(
|
<#field_ty as ::axum::extract::FromRequestParts<_>>::from_request_parts(
|
||||||
&mut parts,
|
&mut parts,
|
||||||
state,
|
state,
|
||||||
)
|
)
|
||||||
|
@ -540,7 +538,7 @@ fn extract_fields(
|
||||||
Trait::FromRequestParts => {
|
Trait::FromRequestParts => {
|
||||||
quote_spanned! {ty_span=>
|
quote_spanned! {ty_span=>
|
||||||
#member: {
|
#member: {
|
||||||
<#field_ty as ::axum::extract::FromRequestParts<#trait_generics>>::from_request_parts(
|
<#field_ty as ::axum::extract::FromRequestParts<_>>::from_request_parts(
|
||||||
parts,
|
parts,
|
||||||
state,
|
state,
|
||||||
)
|
)
|
||||||
|
@ -565,7 +563,7 @@ fn extract_fields(
|
||||||
#member: {
|
#member: {
|
||||||
let (mut parts, body) = req.into_parts();
|
let (mut parts, body) = req.into_parts();
|
||||||
let value =
|
let value =
|
||||||
<#field_ty as ::axum::extract::FromRequestParts<#trait_generics>>::from_request_parts(
|
<#field_ty as ::axum::extract::FromRequestParts<_>>::from_request_parts(
|
||||||
&mut parts,
|
&mut parts,
|
||||||
state,
|
state,
|
||||||
)
|
)
|
||||||
|
@ -580,7 +578,7 @@ fn extract_fields(
|
||||||
Trait::FromRequestParts => {
|
Trait::FromRequestParts => {
|
||||||
quote_spanned! {ty_span=>
|
quote_spanned! {ty_span=>
|
||||||
#member: {
|
#member: {
|
||||||
<#field_ty as ::axum::extract::FromRequestParts<#trait_generics>>::from_request_parts(
|
<#field_ty as ::axum::extract::FromRequestParts<_>>::from_request_parts(
|
||||||
parts,
|
parts,
|
||||||
state,
|
state,
|
||||||
)
|
)
|
||||||
|
@ -608,7 +606,7 @@ fn extract_fields(
|
||||||
let field_ty = into_outer(&via, ty_span, peel_option(&field.ty).unwrap());
|
let field_ty = into_outer(&via, ty_span, peel_option(&field.ty).unwrap());
|
||||||
quote_spanned! {ty_span=>
|
quote_spanned! {ty_span=>
|
||||||
#member: {
|
#member: {
|
||||||
<#field_ty as ::axum::extract::FromRequest<#trait_generics, _>>::from_request(req, state)
|
<#field_ty as ::axum::extract::FromRequest<_, _>>::from_request(req, state)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.map(#into_inner)
|
.map(#into_inner)
|
||||||
|
@ -618,7 +616,7 @@ fn extract_fields(
|
||||||
let field_ty = into_outer(&via, ty_span, peel_result_ok(&field.ty).unwrap());
|
let field_ty = into_outer(&via, ty_span, peel_result_ok(&field.ty).unwrap());
|
||||||
quote_spanned! {ty_span=>
|
quote_spanned! {ty_span=>
|
||||||
#member: {
|
#member: {
|
||||||
<#field_ty as ::axum::extract::FromRequest<#trait_generics, _>>::from_request(req, state)
|
<#field_ty as ::axum::extract::FromRequest<_, _>>::from_request(req, state)
|
||||||
.await
|
.await
|
||||||
.map(#into_inner)
|
.map(#into_inner)
|
||||||
},
|
},
|
||||||
|
@ -633,7 +631,7 @@ fn extract_fields(
|
||||||
|
|
||||||
quote_spanned! {ty_span=>
|
quote_spanned! {ty_span=>
|
||||||
#member: {
|
#member: {
|
||||||
<#field_ty as ::axum::extract::FromRequest<#trait_generics, _>>::from_request(req, state)
|
<#field_ty as ::axum::extract::FromRequest<_, _>>::from_request(req, state)
|
||||||
.await
|
.await
|
||||||
.map(#into_inner)
|
.map(#into_inner)
|
||||||
.map_err(#map_err)?
|
.map_err(#map_err)?
|
||||||
|
|
Loading…
Reference in a new issue