This commit is contained in:
2025-07-14 21:18:57 -04:00
parent e18eb7bb02
commit 820f5445a3

View File

@ -14,15 +14,13 @@ pub fn http_response(_attr: TokenStream, item: TokenStream) -> TokenStream {
let impl_block = match &ast.data {
Data::Struct(_) => {
quote! {
#[async_trait::async_trait]
impl Responsable for #name
where
Self: serde::de::DeserializeOwned + Sized,
Self: serde::de::DeserializeOwned + Sized + Send,
{
fn receive(resp: awc::ClientResponse) -> Result<Self, Box<dyn std::error::Error>> {
let parsed = actix_web::rt::System::new()
.block_on(async {
resp.json::<Self>().await
})
async fn receive(mut resp: actix_web::ClientResponse) -> Result<Self, Box<dyn std::error::Error>> {
let parsed = resp.json::<Self>().await
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
Ok(parsed)
}
@ -47,12 +45,10 @@ pub fn http_response(_attr: TokenStream, item: TokenStream) -> TokenStream {
});
quote! {
#[async_trait::async_trait]
impl Responsable for #name {
fn receive(resp: awc::ClientResponse) -> Result<Self, Box<dyn std::error::Error>> {
let body = actix_web::rt::System::new()
.block_on(async {
resp.body().await
})
async fn receive(mut resp: actix_web::ClientResponse) -> Result<Self, Box<dyn std::error::Error>> {
let body = resp.body().await
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
#(#variant_arms)*