mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-04-20 06:54:46 +00:00
apply clippy suggestions
This commit is contained in:
parent
286466fcc9
commit
4429fced3b
7 changed files with 62 additions and 78 deletions
|
@ -25,55 +25,47 @@ pub fn derive_resource(tokens : TokenStream) -> TokenStream
|
|||
#[proc_macro_attribute]
|
||||
pub fn rest_read_all(attr : TokenStream, item : TokenStream) -> TokenStream
|
||||
{
|
||||
let output = expand_method(Method::ReadAll, attr, item);
|
||||
output
|
||||
expand_method(Method::ReadAll, attr, item)
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn rest_read(attr : TokenStream, item : TokenStream) -> TokenStream
|
||||
{
|
||||
let output = expand_method(Method::Read, attr, item);
|
||||
output
|
||||
expand_method(Method::Read, attr, item)
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn rest_search(attr : TokenStream, item : TokenStream) -> TokenStream
|
||||
{
|
||||
let output = expand_method(Method::Search, attr, item);
|
||||
output
|
||||
expand_method(Method::Search, attr, item)
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn rest_create(attr : TokenStream, item : TokenStream) -> TokenStream
|
||||
{
|
||||
let output = expand_method(Method::Create, attr, item);
|
||||
output
|
||||
expand_method(Method::Create, attr, item)
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn rest_update_all(attr : TokenStream, item : TokenStream) -> TokenStream
|
||||
{
|
||||
let output = expand_method(Method::UpdateAll, attr, item);
|
||||
output
|
||||
expand_method(Method::UpdateAll, attr, item)
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn rest_update(attr : TokenStream, item : TokenStream) -> TokenStream
|
||||
{
|
||||
let output = expand_method(Method::Update, attr, item);
|
||||
output
|
||||
expand_method(Method::Update, attr, item)
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn rest_delete_all(attr : TokenStream, item : TokenStream) -> TokenStream
|
||||
{
|
||||
let output = expand_method(Method::DeleteAll, attr, item);
|
||||
output
|
||||
expand_method(Method::DeleteAll, attr, item)
|
||||
}
|
||||
|
||||
#[proc_macro_attribute]
|
||||
pub fn rest_delete(attr : TokenStream, item : TokenStream) -> TokenStream
|
||||
{
|
||||
let output = expand_method(Method::Delete, attr, item);
|
||||
output
|
||||
expand_method(Method::Delete, attr, item)
|
||||
}
|
||||
|
|
|
@ -99,19 +99,11 @@ pub fn expand_method(method : Method, attrs : TokenStream, item : TokenStream) -
|
|||
},
|
||||
FnArg::Receiver(_) => panic!("didn't expect self parameter")
|
||||
}).collect();
|
||||
let mut generics : Vec<TokenStream2> = Vec::new();
|
||||
for i in 1..args.len()
|
||||
{
|
||||
let (_, ty) = &args[i];
|
||||
generics.push(quote!(#ty));
|
||||
}
|
||||
let mut generics : Vec<TokenStream2> = args.iter().skip(1).map(|(_, ty)| quote!(#ty)).collect();
|
||||
generics.push(quote!(#ret));
|
||||
let args : Vec<TokenStream2> = args.into_iter().map(|(pat, ty)| quote!(#pat : #ty)).collect();
|
||||
let block = fun.block.stmts;
|
||||
let ret_stmt = match is_no_content {
|
||||
true => Some(quote!(().into())),
|
||||
false => None
|
||||
};
|
||||
let ret_stmt = if is_no_content { Some(quote!(#ret::default())) } else { None };
|
||||
|
||||
let trait_ident = method.trait_ident();
|
||||
let fn_ident = method.fn_ident();
|
||||
|
|
|
@ -73,7 +73,7 @@ fn expand_field(field : &Field) -> TokenStream2
|
|||
let ty = &field.ty;
|
||||
|
||||
quote! {{
|
||||
let mut schema = <#ty>::to_schema();
|
||||
let mut schema = <#ty>::schema();
|
||||
|
||||
if schema.nullable
|
||||
{
|
||||
|
@ -105,7 +105,7 @@ fn expand_field(field : &Field) -> TokenStream2
|
|||
None => {
|
||||
properties.insert(
|
||||
stringify!(#ident).to_string(),
|
||||
ReferenceOr::Item(Box::new(schema.to_schema()))
|
||||
ReferenceOr::Item(Box::new(schema.into_schema()))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ pub fn expand_struct(input : ItemStruct) -> TokenStream2
|
|||
quote!{
|
||||
impl #generics ::gotham_restful::OpenapiType for #ident #generics
|
||||
{
|
||||
fn to_schema() -> ::gotham_restful::OpenapiSchema
|
||||
fn schema() -> ::gotham_restful::OpenapiSchema
|
||||
{
|
||||
use ::gotham_restful::{export::{openapi::*, IndexMap}, OpenapiSchema};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue