mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +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 async fn request<T: DeserializeOwned, R: Request<T>>(
|
||||
pub async fn request<T: DeserializeOwned, R: Request<ReturnValue = T>>(
|
||||
client: &Client,
|
||||
request: R,
|
||||
) -> ResponseResult<T> {
|
||||
|
|
|
@ -8,7 +8,9 @@ pub struct GetMe {
|
|||
token: String,
|
||||
}
|
||||
|
||||
impl Request<User> for GetMe {
|
||||
impl Request for GetMe {
|
||||
type ReturnValue = User;
|
||||
|
||||
fn name(&self) -> &str {
|
||||
"getMe"
|
||||
}
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
use reqwest::r#async::multipart::Form;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
/// Request that can be sended to telegram.
|
||||
/// `R` - return type.
|
||||
pub trait Request<R: serde::de::DeserializeOwned> {
|
||||
/// `ReturnValue` - a type that will be returned from Telegram.
|
||||
pub trait Request {
|
||||
type ReturnValue: DeserializeOwned;
|
||||
|
||||
/// Get name of the request (e.g. "getMe" or "sendMessage")
|
||||
fn name(&self) -> &str;
|
||||
|
||||
|
|
|
@ -21,7 +21,9 @@ pub struct SendMessage {
|
|||
reply_markup: Option<()>, // TODO: ReplyMarkup enum
|
||||
}
|
||||
|
||||
impl Request<Message> for SendMessage {
|
||||
impl Request for SendMessage {
|
||||
type ReturnValue = Message;
|
||||
|
||||
fn name(&self) -> &str {
|
||||
"getMe"
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue