This commit is contained in:
2025-07-14 14:49:44 -04:00
parent e96def50f3
commit d82f663c27

View File

@ -132,12 +132,21 @@ pub fn derive_http_response(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as DeriveInput);
let name = &input.ident;
let expanded = quote! {
impl #name {
pub async fn receive(resp: awc::ClientResponse) -> Result<Self, std::error::Error> {
resp.json().await
let expanded = match &input.data {
Data::Struct(_) => {
quote! {
impl Responsable for #name {
fn receive(resp: actix_web::ClientResponse) -> Result<Self, std::error::Error> {
let parsed = actix_web::rt::System::new()
.block_on(async { resp.json::<#name>().await })
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
Ok(parsed)
}
}
}
}
_ => panic!("#[derive(HttpResponse)] only supports structs"),
};
TokenStream::from(expanded)