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 {
|
||||
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)*
|
||||
|
Reference in New Issue
Block a user