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