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 input = parse_macro_input!(input as DeriveInput);
|
||||||
let name = &input.ident;
|
let name = &input.ident;
|
||||||
|
|
||||||
// Extract base_url from #[http_get(url = "...")]
|
// Extract #[http_get(url = "...")]
|
||||||
let mut base_url_lit = None;
|
let mut base_url_lit = None;
|
||||||
for attr in &input.attrs {
|
for attr in &input.attrs {
|
||||||
if attr.path().is_ident("http_get") {
|
if attr.path().is_ident("http_get") {
|
||||||
@ -46,7 +46,10 @@ pub fn derive_http_get_request(input: TokenStream) -> TokenStream {
|
|||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl Queryable for #name {
|
impl ::Queryable for #name
|
||||||
|
where
|
||||||
|
Self: serde::de::DeserializeOwned,
|
||||||
|
{
|
||||||
fn send(
|
fn send(
|
||||||
&self,
|
&self,
|
||||||
headers: Option<Vec<(&str, &str)>>,
|
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()
|
let parsed = actix_web::rt::System::new()
|
||||||
.block_on(async { request.send().await })
|
.block_on(async {
|
||||||
|
request
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.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()))?;
|
||||||
|
|
||||||
let body_bytes = actix_web::rt::System::new()
|
Ok(Response::receive(parsed)?)
|
||||||
.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)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -106,7 +108,7 @@ pub fn derive_http_get_request(input: TokenStream) -> TokenStream {
|
|||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
quote! {
|
quote! {
|
||||||
impl Queryable for #name {
|
impl ::Queryable for #name {
|
||||||
fn send(
|
fn send(
|
||||||
&self,
|
&self,
|
||||||
headers: Option<Vec<(&str, &str)>>,
|
headers: Option<Vec<(&str, &str)>>,
|
||||||
|
Reference in New Issue
Block a user