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 input = parse_macro_input!(input as DeriveInput);
|
||||||
let name = &input.ident;
|
let name = &input.ident;
|
||||||
|
|
||||||
let expanded = quote! {
|
let expanded = match &input.data {
|
||||||
impl #name {
|
Data::Struct(_) => {
|
||||||
pub async fn receive(resp: awc::ClientResponse) -> Result<Self, std::error::Error> {
|
quote! {
|
||||||
resp.json().await
|
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)
|
TokenStream::from(expanded)
|
||||||
|
Reference in New Issue
Block a user