made use serde instead of bytes
This commit is contained in:
28
src/lib.rs
28
src/lib.rs
@ -7,7 +7,7 @@ pub fn derive_http_get_request(input: TokenStream) -> TokenStream {
|
||||
let input = parse_macro_input!(input as DeriveInput);
|
||||
let name = &input.ident;
|
||||
|
||||
// Extract base_url from #[http_get(url = "...")]
|
||||
// Extract #[http_get(url = "...")]
|
||||
let mut base_url_lit = None;
|
||||
for attr in &input.attrs {
|
||||
if attr.path().is_ident("http_get") {
|
||||
@ -46,7 +46,10 @@ pub fn derive_http_get_request(input: TokenStream) -> TokenStream {
|
||||
}).collect();
|
||||
|
||||
quote! {
|
||||
impl Queryable for #name {
|
||||
impl ::Queryable for #name
|
||||
where
|
||||
Self: serde::de::DeserializeOwned,
|
||||
{
|
||||
fn send(
|
||||
&self,
|
||||
headers: Option<Vec<(&str, &str)>>,
|
||||
@ -75,18 +78,17 @@ pub fn derive_http_get_request(input: TokenStream) -> TokenStream {
|
||||
}
|
||||
}
|
||||
|
||||
let response = actix_web::rt::System::new()
|
||||
.block_on(async { request.send().await })
|
||||
let parsed = actix_web::rt::System::new()
|
||||
.block_on(async {
|
||||
request
|
||||
.send()
|
||||
.await?
|
||||
.json::<Self>()
|
||||
.await
|
||||
})
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
||||
|
||||
let body_bytes = actix_web::rt::System::new()
|
||||
.block_on(async { response.body().await })
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
||||
|
||||
let body = Response::receive(body_bytes.to_vec())
|
||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e.to_string()))?;
|
||||
|
||||
Ok(body)
|
||||
Ok(Response::receive(parsed)?)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,7 +108,7 @@ pub fn derive_http_get_request(input: TokenStream) -> TokenStream {
|
||||
}).collect();
|
||||
|
||||
quote! {
|
||||
impl Queryable for #name {
|
||||
impl ::Queryable for #name {
|
||||
fn send(
|
||||
&self,
|
||||
headers: Option<Vec<(&str, &str)>>,
|
||||
|
Reference in New Issue
Block a user