11use proc_macro:: TokenStream ;
22use proc_macro2:: { Ident , TokenTree } ;
3- use quote:: { quote , ToTokens } ;
4- use syn:: { spanned :: Spanned , Attribute , Field , ItemStruct } ;
3+ use quote:: { ToTokens , quote } ;
4+ use syn:: { Attribute , Field , ItemStruct , spanned :: Spanned } ;
55
66#[ proc_macro_derive( Typesense , attributes( typesense) ) ]
77pub fn typesense_collection_derive ( input : TokenStream ) -> TokenStream {
@@ -79,7 +79,7 @@ fn impl_typesense_collection(item: ItemStruct) -> syn::Result<TokenStream> {
7979 proc_macro2:: TokenStream :: new ( )
8080 } ;
8181
82- let gen = quote ! {
82+ let g = quote ! {
8383 impl #impl_generics typesense:: document:: Document for #ident #ty_generics #where_clause {
8484 fn collection_schema( ) -> typesense:: collection_schema:: CollectionSchema {
8585 let name = #collection_name. to_owned( ) ;
@@ -94,18 +94,18 @@ fn impl_typesense_collection(item: ItemStruct) -> syn::Result<TokenStream> {
9494 }
9595 }
9696 } ;
97- Ok ( gen . into ( ) )
97+ Ok ( g . into ( ) )
9898}
9999
100- // Get the inner type for a given wrappper
100+ // Get the inner type for a given wrapper
101101fn ty_inner_type < ' a > ( ty : & ' a syn:: Type , wrapper : & ' static str ) -> Option < & ' a syn:: Type > {
102- if let syn:: Type :: Path ( ref p) = ty {
102+ if let syn:: Type :: Path ( p) = ty {
103103 if p. path . segments . len ( ) == 1 && p. path . segments [ 0 ] . ident == wrapper {
104104 if let syn:: PathArguments :: AngleBracketed ( ref inner_ty) = p. path . segments [ 0 ] . arguments {
105105 if inner_ty. args . len ( ) == 1 {
106106 // len is 1 so this should not fail
107107 let inner_ty = inner_ty. args . first ( ) . unwrap ( ) ;
108- if let syn:: GenericArgument :: Type ( ref t) = inner_ty {
108+ if let syn:: GenericArgument :: Type ( t) = inner_ty {
109109 return Some ( t) ;
110110 }
111111 }
@@ -198,7 +198,7 @@ fn extract_attrs(attrs: Vec<Attribute>) -> syn::Result<Attrs> {
198198 return Err ( syn:: Error :: new (
199199 tt. span ( ) ,
200200 "Expected boolean, without quotation marks (\" \" )" ,
201- ) )
201+ ) ) ;
202202 }
203203 } ;
204204 res. enable_nested_fields = Some ( val) ;
@@ -250,10 +250,13 @@ fn to_typesense_field_type(field: &Field) -> syn::Result<proc_macro2::TokenStrea
250250 return Some ( Err ( syn:: Error :: new_spanned (
251251 tt,
252252 format ! ( "Unexpected token {}. Did you mean `facet`?" , tt) ,
253- ) ) )
253+ ) ) ) ;
254254 }
255255 None => {
256- return Some ( Err ( syn:: Error :: new_spanned ( attr, "expected `facet`" ) ) )
256+ return Some ( Err ( syn:: Error :: new_spanned (
257+ attr,
258+ "expected `facet`" ,
259+ ) ) ) ;
257260 }
258261 }
259262
0 commit comments