Advertisement
Guest User

Untitled

a guest
Jul 14th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.47 KB | None | 0 0
  1. use crate::error::TPError;
  2. use reqwest::Url;
  3. use serde::Deserialize;
  4.  
  5. pub trait FromQuery<'de>: Sized
  6. {
  7.    type RecvType: Deserialize<'de> + Into<Self>;
  8.  
  9.     fn api_url(query: &str) -> Result<Url, TPError>;
  10.  
  11.     fn from_query(query: &str) -> Result<Self, TPError>
  12.     {
  13.         Ok(reqwest::get(Self::api_url(query)?)?
  14.             .json::<Self::RecvType>()
  15.             .expect("Failed to parse API response. Did the external API change?")
  16.             .into())
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement