@@ -4,7 +4,7 @@ use proc_macro2::{Span, TokenStream};
44use quote:: { quote, quote_spanned} ;
55use syn:: parse:: Parser as _;
66use syn:: spanned:: Spanned ;
7- use syn:: { FnArg , Ident , ItemFn , LitStr , PatType } ;
7+ use syn:: { FnArg , Ident , ItemFn , LitStr } ;
88
99#[ derive( Default ) ]
1010pub ( crate ) struct ReducerArgs {
@@ -59,50 +59,33 @@ impl ReducerArgs {
5959 }
6060}
6161
62- pub ( crate ) fn assert_only_lifetime_generics ( original_function : & ItemFn , function_kind_plural : & str ) -> syn:: Result < ( ) > {
62+ pub ( crate ) fn reducer_impl ( args : ReducerArgs , original_function : & ItemFn ) -> syn:: Result < TokenStream > {
63+ let func_name = & original_function. sig . ident ;
64+ let vis = & original_function. vis ;
65+
66+ let reducer_name = args. name . unwrap_or_else ( || ident_to_litstr ( func_name) ) ;
67+
6368 for param in & original_function. sig . generics . params {
6469 let err = |msg| syn:: Error :: new_spanned ( param, msg) ;
6570 match param {
6671 syn:: GenericParam :: Lifetime ( _) => { }
67- syn:: GenericParam :: Type ( _) => {
68- return Err ( err ( format ! (
69- "type parameters are not allowed on {function_kind_plural}"
70- ) ) )
71- }
72- syn:: GenericParam :: Const ( _) => {
73- return Err ( err ( format ! (
74- "const parameters are not allowed on {function_kind_plural}"
75- ) ) )
76- }
72+ syn:: GenericParam :: Type ( _) => return Err ( err ( "type parameters are not allowed on reducers" ) ) ,
73+ syn:: GenericParam :: Const ( _) => return Err ( err ( "const parameters are not allowed on reducers" ) ) ,
7774 }
7875 }
79- Ok ( ( ) )
80- }
8176
82- /// Extract all function parameters, except for `self` ones that aren't allowed.
83- pub ( crate ) fn extract_typed_args ( original_function : & ItemFn ) -> syn:: Result < Vec < & PatType > > {
84- original_function
77+ let lifecycle = args. lifecycle . iter ( ) . filter_map ( |lc| lc. to_lifecycle_value ( ) ) ;
78+
79+ // Extract all function parameters, except for `self` ones that aren't allowed.
80+ let typed_args = original_function
8581 . sig
8682 . inputs
8783 . iter ( )
8884 . map ( |arg| match arg {
8985 FnArg :: Typed ( arg) => Ok ( arg) ,
9086 _ => Err ( syn:: Error :: new_spanned ( arg, "expected typed argument" ) ) ,
9187 } )
92- . collect ( )
93- }
94-
95- pub ( crate ) fn reducer_impl ( args : ReducerArgs , original_function : & ItemFn ) -> syn:: Result < TokenStream > {
96- let func_name = & original_function. sig . ident ;
97- let vis = & original_function. vis ;
98-
99- let reducer_name = args. name . unwrap_or_else ( || ident_to_litstr ( func_name) ) ;
100-
101- assert_only_lifetime_generics ( original_function, "reducers" ) ?;
102-
103- let lifecycle = args. lifecycle . iter ( ) . filter_map ( |lc| lc. to_lifecycle_value ( ) ) ;
104-
105- let typed_args = extract_typed_args ( original_function) ?;
88+ . collect :: < syn:: Result < Vec < _ > > > ( ) ?;
10689
10790 // Extract all function parameter names.
10891 let opt_arg_names = typed_args. iter ( ) . map ( |arg| {
@@ -158,8 +141,6 @@ pub(crate) fn reducer_impl(args: ReducerArgs, original_function: &ItemFn) -> syn
158141 #[ automatically_derived]
159142 impl spacetimedb:: rt:: FnInfo for #func_name {
160143 type Invoke = spacetimedb:: rt:: ReducerFn ;
161- /// The function kind, which will cause scheduled tables to accept reducers.
162- type FnKind = spacetimedb:: rt:: FnKindReducer ;
163144 const NAME : & ' static str = #reducer_name;
164145 #( const LIFECYCLE : Option <spacetimedb:: rt:: LifecycleReducer > = Some ( #lifecycle) ; ) *
165146 const ARG_NAMES : & ' static [ Option <& ' static str >] = & [ #( #opt_arg_names) , * ] ;
0 commit comments