Use a type alias instead of a generic in Request

This commit is contained in:
Temirkhan Myrzamadi 2019-09-02 16:29:29 +06:00
parent cad60fa2fb
commit c4fcc13dcd
4 changed files with 12 additions and 5 deletions

View file

@ -20,7 +20,7 @@ pub enum RequestError {
pub type ResponseResult<T> = Result<T, RequestError>; pub type ResponseResult<T> = Result<T, RequestError>;
pub async fn request<T: DeserializeOwned, R: Request<T>>( pub async fn request<T: DeserializeOwned, R: Request<ReturnValue = T>>(
client: &Client, client: &Client,
request: R, request: R,
) -> ResponseResult<T> { ) -> ResponseResult<T> {

View file

@ -8,7 +8,9 @@ pub struct GetMe {
token: String, token: String,
} }
impl Request<User> for GetMe { impl Request for GetMe {
type ReturnValue = User;
fn name(&self) -> &str { fn name(&self) -> &str {
"getMe" "getMe"
} }

View file

@ -1,8 +1,11 @@
use reqwest::r#async::multipart::Form; use reqwest::r#async::multipart::Form;
use serde::de::DeserializeOwned;
/// Request that can be sended to telegram. /// Request that can be sended to telegram.
/// `R` - return type. /// `ReturnValue` - a type that will be returned from Telegram.
pub trait Request<R: serde::de::DeserializeOwned> { pub trait Request {
type ReturnValue: DeserializeOwned;
/// Get name of the request (e.g. "getMe" or "sendMessage") /// Get name of the request (e.g. "getMe" or "sendMessage")
fn name(&self) -> &str; fn name(&self) -> &str;

View file

@ -21,7 +21,9 @@ pub struct SendMessage {
reply_markup: Option<()>, // TODO: ReplyMarkup enum reply_markup: Option<()>, // TODO: ReplyMarkup enum
} }
impl Request<Message> for SendMessage { impl Request for SendMessage {
type ReturnValue = Message;
fn name(&self) -> &str { fn name(&self) -> &str {
"getMe" "getMe"
} }