mirror of https://github.com/fafhrd91/actix-web
remove useless ResourceType
this is dead code from back when .to and .to_async were different ways to add a service
This commit is contained in:
parent
df25c254a5
commit
4e8eb74600
|
@ -3,21 +3,9 @@ use std::{collections::HashSet, convert::TryFrom};
|
||||||
use actix_router::ResourceDef;
|
use actix_router::ResourceDef;
|
||||||
use proc_macro::TokenStream;
|
use proc_macro::TokenStream;
|
||||||
use proc_macro2::{Span, TokenStream as TokenStream2};
|
use proc_macro2::{Span, TokenStream as TokenStream2};
|
||||||
use quote::{format_ident, quote, ToTokens, TokenStreamExt};
|
use quote::{quote, ToTokens, TokenStreamExt};
|
||||||
use syn::{parse_macro_input, AttributeArgs, Ident, LitStr, Meta, NestedMeta, Path};
|
use syn::{parse_macro_input, AttributeArgs, Ident, LitStr, Meta, NestedMeta, Path};
|
||||||
|
|
||||||
enum ResourceType {
|
|
||||||
Async,
|
|
||||||
Sync,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToTokens for ResourceType {
|
|
||||||
fn to_tokens(&self, stream: &mut TokenStream2) {
|
|
||||||
let ident = format_ident!("to");
|
|
||||||
stream.append(ident);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! method_type {
|
macro_rules! method_type {
|
||||||
(
|
(
|
||||||
$($variant:ident, $upper:ident, $lower:ident,)+
|
$($variant:ident, $upper:ident, $lower:ident,)+
|
||||||
|
@ -213,35 +201,10 @@ pub struct Route {
|
||||||
/// AST of the handler function being annotated.
|
/// AST of the handler function being annotated.
|
||||||
ast: syn::ItemFn,
|
ast: syn::ItemFn,
|
||||||
|
|
||||||
/// TODO: remove
|
|
||||||
resource_type: ResourceType,
|
|
||||||
|
|
||||||
/// The doc comment attributes to copy to generated struct, if any.
|
/// The doc comment attributes to copy to generated struct, if any.
|
||||||
doc_attributes: Vec<syn::Attribute>,
|
doc_attributes: Vec<syn::Attribute>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn guess_resource_type(typ: &syn::Type) -> ResourceType {
|
|
||||||
let mut guess = ResourceType::Sync;
|
|
||||||
|
|
||||||
if let syn::Type::ImplTrait(typ) = typ {
|
|
||||||
for bound in typ.bounds.iter() {
|
|
||||||
if let syn::TypeParamBound::Trait(bound) = bound {
|
|
||||||
for bound in bound.path.segments.iter() {
|
|
||||||
if bound.ident == "Future" {
|
|
||||||
guess = ResourceType::Async;
|
|
||||||
break;
|
|
||||||
} else if bound.ident == "Responder" {
|
|
||||||
guess = ResourceType::Sync;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
guess
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Route {
|
impl Route {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
args: AttributeArgs,
|
args: AttributeArgs,
|
||||||
|
@ -268,25 +231,17 @@ impl Route {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let resource_type = if ast.sig.asyncness.is_some() {
|
if matches!(ast.sig.output, syn::ReturnType::Default) {
|
||||||
ResourceType::Async
|
return Err(syn::Error::new_spanned(
|
||||||
} else {
|
ast,
|
||||||
match ast.sig.output {
|
"Function has no return type. Cannot be used as handler",
|
||||||
syn::ReturnType::Default => {
|
));
|
||||||
return Err(syn::Error::new_spanned(
|
}
|
||||||
ast,
|
|
||||||
"Function has no return type. Cannot be used as handler",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
syn::ReturnType::Type(_, ref typ) => guess_resource_type(typ.as_ref()),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
name,
|
name,
|
||||||
args: vec![args],
|
args: vec![args],
|
||||||
ast,
|
ast,
|
||||||
resource_type,
|
|
||||||
doc_attributes,
|
doc_attributes,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -303,25 +258,17 @@ impl Route {
|
||||||
.cloned()
|
.cloned()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let resource_type = if ast.sig.asyncness.is_some() {
|
if matches!(ast.sig.output, syn::ReturnType::Default) {
|
||||||
ResourceType::Async
|
return Err(syn::Error::new_spanned(
|
||||||
} else {
|
ast,
|
||||||
match ast.sig.output {
|
"Function has no return type. Cannot be used as handler",
|
||||||
syn::ReturnType::Default => {
|
));
|
||||||
return Err(syn::Error::new_spanned(
|
}
|
||||||
ast,
|
|
||||||
"Function has no return type. Cannot be used as handler",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
syn::ReturnType::Type(_, ref typ) => guess_resource_type(typ.as_ref()),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
name,
|
name,
|
||||||
args,
|
args,
|
||||||
ast,
|
ast,
|
||||||
resource_type,
|
|
||||||
doc_attributes,
|
doc_attributes,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -333,7 +280,6 @@ impl ToTokens for Route {
|
||||||
name,
|
name,
|
||||||
ast,
|
ast,
|
||||||
args,
|
args,
|
||||||
resource_type,
|
|
||||||
doc_attributes,
|
doc_attributes,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
|
@ -378,7 +324,7 @@ impl ToTokens for Route {
|
||||||
#method_guards
|
#method_guards
|
||||||
#(.guard(::actix_web::guard::fn_guard(#guards)))*
|
#(.guard(::actix_web::guard::fn_guard(#guards)))*
|
||||||
#(.wrap(#wrappers))*
|
#(.wrap(#wrappers))*
|
||||||
.#resource_type(#name);
|
.to(#name);
|
||||||
|
|
||||||
::actix_web::dev::HttpServiceFactory::register(__resource, __config);
|
::actix_web::dev::HttpServiceFactory::register(__resource, __config);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue