🏗️ Elegant & Highly Performant Async Gemini Server Framework for the Modern Age
async framework gemini-protocol protocol gemini rust
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(rossweisse): Fix all clippy pedantic and nursery lint errors

Fuwn 43fb2c61 4a803481

+46 -44
+1 -1
rossweisse/src/implementations/route.rs
··· 17 17 18 18 use proc_macro::TokenStream; 19 19 20 - pub fn route(_arguments: TokenStream, item: syn::ItemFn) -> TokenStream { 20 + pub fn route(_arguments: TokenStream, item: &syn::ItemFn) -> TokenStream { 21 21 quote::quote! { #item }.into() 22 22 }
+14 -11
rossweisse/src/implementations/router/fields.rs
··· 17 17 18 18 use proc_macro::TokenStream; 19 19 use quote::quote; 20 + use syn::punctuated::Punctuated; 20 21 21 22 pub fn fields(arguments: TokenStream, item: syn::ItemStruct) -> TokenStream { 22 23 let field_initializers = syn::parse_macro_input!( ··· 29 30 ( 30 31 syn::FieldsNamed { 31 32 brace_token: syn::token::Brace::default(), 32 - named: Default::default(), 33 + named: Punctuated::default(), 33 34 }, 34 35 false, 35 36 ), 36 - _ => 37 + syn::Fields::Unnamed(_) => 37 38 panic!( 38 39 "`#[rossweisse::router]` can only be used on `struct`s with named \ 39 40 fields or unit structs" ··· 46 47 .0 47 48 .iter() 48 49 .find(|initialiser| initialiser.ident == name.clone().unwrap()) 49 - .map(|initialiser| &initialiser.expr) 50 - .unwrap_or_else(|| { 51 - default_expressions.push({ 52 - let default_expression: syn::Expr = 53 - syn::parse_quote! { ::std::default::Default::default() }; 50 + .map_or_else( 51 + || { 52 + default_expressions.push({ 53 + let default_expression: syn::Expr = 54 + syn::parse_quote! { ::std::default::Default::default() }; 54 55 55 - default_expression 56 - }); 56 + default_expression 57 + }); 57 58 58 - default_expressions.last().unwrap() 59 - }); 59 + default_expressions.last().unwrap() 60 + }, 61 + |initialiser| &initialiser.expr, 62 + ); 60 63 61 64 quote! { 62 65 #name: #initialiser,
+18 -23
rossweisse/src/implementations/router/methods.rs
··· 25 25 .items 26 26 .iter_mut() 27 27 .filter_map(|item| { 28 - if let syn::ImplItem::Fn(method) = item { 29 - for attribute in method.attrs.iter() { 30 - if attribute.path().is_ident("route") { 31 - let arguments = quote::ToTokens::into_token_stream(attribute) 32 - .to_string() 33 - .trim_end_matches(")]") 34 - .trim_start_matches("#[route(") 35 - .to_string(); 28 + let syn::ImplItem::Fn(method) = item else { 29 + return None; 30 + }; 31 + let route_attrribute = method 32 + .attrs 33 + .iter() 34 + .find(|attribute| attribute.path().is_ident("route"))?; 35 + let arguments = quote::ToTokens::into_token_stream(route_attrribute) 36 + .to_string() 37 + .trim_end_matches(")]") 38 + .trim_start_matches("#[route(") 39 + .to_string(); 36 40 37 - if arguments == "index" { 38 - method.sig.ident = 39 - syn::Ident::new("__router_index", method.sig.ident.span()); 40 - } 41 - 42 - return Some(method.sig.ident.clone()); 43 - } else { 44 - return None; 45 - } 46 - } 47 - 48 - None 49 - } else { 50 - None 41 + if arguments == "index" { 42 + method.sig.ident = 43 + syn::Ident::new("__router_index", method.sig.ident.span()); 51 44 } 45 + 46 + Some(method.sig.ident.clone()) 52 47 }) 53 48 .collect::<Vec<_>>(); 54 49 let (implementation_generics, type_generics, where_clause) = ··· 60 55 format!( 61 56 "/{}", 62 57 if route == "__router_index" { 63 - "".to_string() 58 + String::new() 64 59 } else { 65 60 route.to_string() 66 61 }
+13 -9
rossweisse/src/lib.rs
··· 36 36 /// Marks a `struct` as a router or marks an `impl` block as a router 37 37 /// implementation 38 38 /// 39 + /// # Panics 40 + /// 41 + /// Panics if used on an item that is not a `struct` or `impl` block. 42 + /// 39 43 /// # Examples 40 44 /// 41 45 /// ```rust ··· 57 61 /// ``` 58 62 #[proc_macro_attribute] 59 63 pub fn router(arguments: TokenStream, item: TokenStream) -> TokenStream { 60 - let output = match syn::parse::<Item>(item.clone()) { 64 + match syn::parse::<Item>(item) { 61 65 Ok(Item::Struct(item)) => implementations::fields(arguments, item), 62 66 Ok(Item::Impl(item)) => implementations::methods(arguments, item), 63 67 _ => panic!("`#[rossweisse::router]` can only be used on `struct`s"), 64 - }; 65 - 66 - output.into() 68 + } 67 69 } 68 70 69 71 /// Marks a method of a router implementation as a route to mount 70 72 /// 73 + /// # Panics 74 + /// 75 + /// Panics if used on an item that is not a function. 76 + /// 71 77 /// # Examples 72 78 /// 73 79 /// ```rust ··· 84 90 /// ``` 85 91 #[proc_macro_attribute] 86 92 pub fn route(arguments: TokenStream, item: TokenStream) -> TokenStream { 87 - let output = match syn::parse::<Item>(item.clone()) { 88 - Ok(Item::Fn(item)) => implementations::route(arguments, item), 93 + match syn::parse::<Item>(item) { 94 + Ok(Item::Fn(ref item)) => implementations::route(arguments, item), 89 95 _ => panic!("`#[rossweisse::route]` can only be used on `fn`s"), 90 - }; 91 - 92 - output.into() 96 + } 93 97 }