mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
Use a type alias instead of a generic in Request
This commit is contained in:
parent
cad60fa2fb
commit
c4fcc13dcd
4 changed files with 12 additions and 5 deletions
|
@ -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> {
|
||||||
|
|
|
@ -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"
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue