ud
This commit is contained in:
14
src/lib.rs
14
src/lib.rs
@ -26,18 +26,10 @@ pub fn derive_http_get_request(input: TokenStream) -> TokenStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Determine response type name
|
// Determine response type name
|
||||||
let response_name_str = if let Some(custom_resp) = response_name_opt {
|
let response_name_str = response_name_opt.unwrap_or_else(|| format!("{}Resp", query_name_str));
|
||||||
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 = format_ident!("{}", response_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()));
|
let mut error_type = syn::Path::from(syn::Ident::new("E", proc_macro2::Span::call_site()));
|
||||||
for attr in &input.attrs {
|
for attr in &input.attrs {
|
||||||
if attr.path().is_ident("http_error_type") {
|
if attr.path().is_ident("http_error_type") {
|
||||||
@ -101,7 +93,7 @@ pub fn derive_http_get_request(input: TokenStream) -> TokenStream {
|
|||||||
async fn send(
|
async fn send(
|
||||||
&self,
|
&self,
|
||||||
headers: Option<Vec<(&str, &str)>>,
|
headers: Option<Vec<(&str, &str)>>,
|
||||||
) -> Result<Self::R, #error_type> { // Use the error type here
|
) -> Result<Self::R, #error_type> {
|
||||||
use awc::Client;
|
use awc::Client;
|
||||||
use urlencoding::encode;
|
use urlencoding::encode;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user