1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-20 06:54:46 +00:00

fix some clippy warnings

This commit is contained in:
Dominic 2020-04-25 17:01:16 +02:00
parent 147ea980bf
commit d08d9bea8c
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
7 changed files with 46 additions and 48 deletions

View file

@ -120,6 +120,7 @@ impl Method
}
}
#[allow(clippy::large_enum_variant)]
enum MethodArgumentType
{
StateRef,
@ -176,9 +177,8 @@ impl Spanned for MethodArgument
fn interpret_arg_ty(index : usize, attrs : &[Attribute], name : &str, ty : Type) -> Result<MethodArgumentType, Error>
{
let attr = attrs.into_iter()
.filter(|arg| arg.path.segments.iter().filter(|path| &path.ident.to_string() == "rest_arg").nth(0).is_some())
.nth(0)
let attr = attrs.iter()
.find(|arg| arg.path.segments.iter().any(|path| &path.ident.to_string() == "rest_arg"))
.map(|arg| arg.tokens.to_string());
if cfg!(feature = "auth") && (attr.as_deref() == Some("auth") || (attr.is_none() && name == "auth"))
@ -219,19 +219,17 @@ fn interpret_arg(index : usize, arg : &PatType) -> Result<MethodArgument, Error>
}
#[cfg(feature = "openapi")]
fn expand_operation_id(attrs : &AttributeArgs) -> TokenStream2
fn expand_operation_id(attrs : &[NestedMeta]) -> TokenStream2
{
let mut operation_id : Option<&Lit> = None;
for meta in attrs
{
match meta {
NestedMeta::Meta(Meta::NameValue(kv)) => {
if kv.path.segments.last().map(|p| p.ident.to_string()) == Some("operation_id".to_owned())
{
operation_id = Some(&kv.lit)
}
},
_ => {}
if let NestedMeta::Meta(Meta::NameValue(kv)) = meta
{
if kv.path.segments.last().map(|p| p.ident.to_string()) == Some("operation_id".to_owned())
{
operation_id = Some(&kv.lit)
}
}
}
@ -247,25 +245,23 @@ fn expand_operation_id(attrs : &AttributeArgs) -> TokenStream2
}
#[cfg(not(feature = "openapi"))]
fn expand_operation_id(_ : &AttributeArgs) -> TokenStream2
fn expand_operation_id(_ : &[NestedMeta]) -> TokenStream2
{
quote!()
}
fn expand_wants_auth(attrs : &AttributeArgs, default : bool) -> TokenStream2
fn expand_wants_auth(attrs : &[NestedMeta], default : bool) -> TokenStream2
{
let default_lit = Lit::Bool(LitBool { value: default, span: Span::call_site() });
let mut wants_auth = &default_lit;
for meta in attrs
{
match meta {
NestedMeta::Meta(Meta::NameValue(kv)) => {
if kv.path.segments.last().map(|p| p.ident.to_string()) == Some("wants_auth".to_owned())
{
wants_auth = &kv.lit
}
},
_ => {}
if let NestedMeta::Meta(Meta::NameValue(kv)) = meta
{
if kv.path.segments.last().map(|p| p.ident.to_string()) == Some("wants_auth".to_owned())
{
wants_auth = &kv.lit
}
}
}
@ -277,6 +273,7 @@ fn expand_wants_auth(attrs : &AttributeArgs, default : bool) -> TokenStream2
}
}
#[allow(clippy::comparison_chain)]
fn expand(method : Method, attrs : TokenStream, item : TokenStream) -> Result<TokenStream2, Error>
{
let krate = super::krate();
@ -381,7 +378,7 @@ fn expand(method : Method, attrs : TokenStream, item : TokenStream) -> Result<To
{
block = quote!(#block; Default::default())
}
if let Some(arg) = args.iter().filter(|arg| (*arg).ty.is_database_conn()).nth(0)
if let Some(arg) = args.iter().find(|arg| (*arg).ty.is_database_conn())
{
if fun_is_async
{
@ -403,7 +400,7 @@ fn expand(method : Method, attrs : TokenStream, item : TokenStream) -> Result<To
}
};
}
if let Some(arg) = args.iter().filter(|arg| (*arg).ty.is_auth_status()).nth(0)
if let Some(arg) = args.iter().find(|arg| (*arg).ty.is_auth_status())
{
let auth_ty = arg.ty.quote_ty();
state_block = quote! {

View file

@ -44,22 +44,20 @@ fn expand_where(generics : &Generics) -> TokenStream2
{
if generics.params.is_empty()
{
quote!()
return quote!();
}
else
{
let krate = super::krate();
let idents = generics.params.iter()
.map(|param| match param {
GenericParam::Type(ty) => Some(ty.ident.clone()),
_ => None
})
.filter(|param| param.is_some())
.map(|param| param.unwrap());
quote! {
where #(#idents : #krate::OpenapiType),*
}
let krate = super::krate();
let idents = generics.params.iter()
.map(|param| match param {
GenericParam::Type(ty) => Some(ty.ident.clone()),
_ => None
})
.filter(|param| param.is_some())
.map(|param| param.unwrap());
quote! {
where #(#idents : #krate::OpenapiType),*
}
}
@ -98,8 +96,7 @@ fn remove_parens(input : TokenStream2) -> TokenStream2
}
Box::new(iter::once(tt))
});
let output = TokenStream2::from_iter(iter);
output
TokenStream2::from_iter(iter)
}
fn parse_attributes(input : &[Attribute]) -> Result<Attrs, Error>

View file

@ -67,7 +67,7 @@ fn expand(tokens : TokenStream) -> Result<TokenStream2, Error>
.filter(|attr| attr.path.segments.iter().last().map(|segment| segment.ident.to_string()) == Some("supported_types".to_string()))
.flat_map(|attr|
syn::parse2::<MimeList>(attr.tokens)
.map(|list| Box::new(list.0.into_iter().map(|mime| Ok(mime))) as Box<dyn Iterator<Item = Result<Path, Error>>>)
.map(|list| Box::new(list.0.into_iter().map(Ok)) as Box<dyn Iterator<Item = Result<Path, Error>>>)
.unwrap_or_else(|err| Box::new(iter::once(Err(err)))))
.collect_to_result()?;