diff --git a/server_fn/server_fn_macro_default/src/lib.rs b/server_fn/server_fn_macro_default/src/lib.rs index fbd25da52..2d1598705 100644 --- a/server_fn/server_fn_macro_default/src/lib.rs +++ b/server_fn/server_fn_macro_default/src/lib.rs @@ -33,6 +33,7 @@ use syn::__private::ToTokens; /// - `endpoint`: specifies the exact path at which the server function handler will be mounted, /// relative to the prefix (defaults to the function name followed by unique hash) /// - `input`: the encoding for the arguments (defaults to `PostUrl`) +/// - `input_derive`: a list of derives to be added on the generated input struct (defaults to `(Clone, serde::Serialize, serde::Deserialize)` if `input` is set to a custom struct, won't have an effect otherwise) /// - `output`: the encoding for the response (defaults to `Json`) /// - `client`: a custom `Client` implementation that will be used for this server fn /// - `encoding`: (legacy, may be deprecated in future) specifies the encoding, which may be one diff --git a/server_fn_macro/src/lib.rs b/server_fn_macro/src/lib.rs index b25281a22..b4cd3a406 100644 --- a/server_fn_macro/src/lib.rs +++ b/server_fn_macro/src/lib.rs @@ -112,6 +112,7 @@ pub fn server_macro_impl( struct_name, prefix, input, + input_derive, output, fn_path, builtin_encoding, @@ -402,12 +403,18 @@ pub fn server_macro_impl( Clone, #server_fn_path::serde_lite::Serialize, #server_fn_path::serde_lite::Deserialize }, ), - _ => ( - PathInfo::Serde, - quote! { - Clone, #server_fn_path::serde::Serialize, #server_fn_path::serde::Deserialize - }, - ), + _ => match input_derive { + Some(derives) => { + let d = derives.elems; + (PathInfo::None, quote! { #d }) + } + None => ( + PathInfo::Serde, + quote! { + Clone, #server_fn_path::serde::Serialize, #server_fn_path::serde::Deserialize + }, + ), + }, }; let addl_path = match path { PathInfo::Serde => quote! { @@ -673,6 +680,7 @@ struct ServerFnArgs { struct_name: Option, prefix: Option, input: Option, + input_derive: Option, output: Option, fn_path: Option, req_ty: Option, @@ -693,6 +701,7 @@ impl Parse for ServerFnArgs { // new arguments: can only be keyed by name let mut input: Option = None; + let mut input_derive: Option = None; let mut output: Option = None; let mut req_ty: Option = None; let mut res_ty: Option = None; @@ -760,6 +769,14 @@ impl Parse for ServerFnArgs { )); } input = Some(stream.parse()?); + } else if key == "input_derive" { + if input_derive.is_some() { + return Err(syn::Error::new( + key.span(), + "keyword argument repeated: `input_derive`", + )); + } + input_derive = Some(stream.parse()?); } else if key == "output" { if encoding.is_some() { return Err(syn::Error::new( @@ -902,6 +919,7 @@ impl Parse for ServerFnArgs { struct_name, prefix, input, + input_derive, output, fn_path, builtin_encoding,