This commit is contained in:
2025-06-30 12:11:49 -04:00
parent 83d5d85962
commit b37f386fe8

View File

@ -26,18 +26,10 @@ pub fn derive_http_get_request(input: TokenStream) -> TokenStream {
}
// Determine response type name
let response_name_str = if let Some(custom_resp) = response_name_opt {
custom_resp
} else if query_name_str == "Q" {
"R".to_string()
} else if query_name_str.ends_with('Q') {
format!("{}R", &query_name_str[..query_name_str.len() - 1])
} else {
panic!("HttpRequest derive macro expects the type name to be 'Q' or end with 'Q', or specify #[http_response = \"...\"] to override");
};
let response_name_str = response_name_opt.unwrap_or_else(|| format!("{}Resp", query_name_str));
let response_name = format_ident!("{}", response_name_str);
// Parse optional #[http_error_type = "..."] attribute (default to `current_mod::E`)
// Parse optional #[http_error_type = "..."] attribute (default to `E`)
let mut error_type = syn::Path::from(syn::Ident::new("E", proc_macro2::Span::call_site()));
for attr in &input.attrs {
if attr.path().is_ident("http_error_type") {
@ -101,7 +93,7 @@ pub fn derive_http_get_request(input: TokenStream) -> TokenStream {
async fn send(
&self,
headers: Option<Vec<(&str, &str)>>,
) -> Result<Self::R, #error_type> { // Use the error type here
) -> Result<Self::R, #error_type> {
use awc::Client;
use urlencoding::encode;