update
This commit is contained in:
17
src/lib.rs
17
src/lib.rs
@ -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)
|
||||
|
Reference in New Issue
Block a user