From be084a5d1d899321f630bbf513119a7df90da5ae Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Mon, 8 Jan 2024 21:51:01 -0500 Subject: [PATCH] remove list of magic identifiers, use rust-analyzer to help with imports instead --- server_fn_macro/src/lib.rs | 46 +++++++++++++------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/server_fn_macro/src/lib.rs b/server_fn_macro/src/lib.rs index e6e90486c..275eb6631 100644 --- a/server_fn_macro/src/lib.rs +++ b/server_fn_macro/src/lib.rs @@ -74,10 +74,20 @@ pub fn server_macro_impl( } = args; let prefix = prefix.unwrap_or_else(|| Literal::string(default_path)); let fn_path = fn_path.unwrap_or_else(|| Literal::string("")); - let input_ident = input.unwrap_or_else(|| syn::parse_quote!(PostUrl)); - let input = codec_ident(server_fn_path.as_ref(), input_ident.clone()); - let output = output.unwrap_or_else(|| syn::parse_quote!(Json)); - let output = codec_ident(server_fn_path.as_ref(), output); + let input_ident = input + .as_ref() + .map(ToString::to_string) + .unwrap_or_else(|| "PostUrl".to_string()); + let input = input.map(|n| n.to_token_stream()).unwrap_or_else(|| { + quote! { + #server_fn_path::codec::PostUrl + } + }); + let output = output.map(|n| n.to_token_stream()).unwrap_or_else(|| { + quote! { + #server_fn_path::codec::Json + } + }); // default to PascalCase version of function name if no struct name given let struct_name = struct_name.unwrap_or_else(|| { let upper_camel_case_name = Converter::new() @@ -306,7 +316,7 @@ pub fn server_macro_impl( } }; - let (is_serde, derives) = match input_ident.to_string().as_str() { + let (is_serde, derives) = match input_ident.as_str() { "Rkyv" => todo!("implement derives for Rkyv"), "MultipartFormData" => (false, quote! {}), "SerdeLite" => ( @@ -835,29 +845,3 @@ impl ServerFnBody { } } } - -/// Returns either the path of the codec (if it's a builtin) or the -/// original ident. -fn codec_ident(server_fn_path: Option<&Path>, ident: Ident) -> TokenStream2 { - if let Some(server_fn_path) = server_fn_path { - let str = ident.to_string(); - if [ - "GetUrl", - "PostUrl", - "Cbor", - "Json", - "Rkyv", - "Streaming", - "StreamingText", - "MultipartFormData", - ] - .contains(&str.as_str()) - { - return quote! { - #server_fn_path::codec::#ident - }; - } - } - - ident.into_token_stream() -}