diff --git a/src/core/network/mod.rs b/src/core/network/mod.rs index f1dc7b1a..86df2c2d 100644 --- a/src/core/network/mod.rs +++ b/src/core/network/mod.rs @@ -20,7 +20,7 @@ pub enum RequestError { pub type ResponseResult = Result; -pub async fn request>( +pub async fn request>( client: &Client, request: R, ) -> ResponseResult { diff --git a/src/core/requests/get_me.rs b/src/core/requests/get_me.rs index decf17f8..de8353b1 100644 --- a/src/core/requests/get_me.rs +++ b/src/core/requests/get_me.rs @@ -8,7 +8,9 @@ pub struct GetMe { token: String, } -impl Request for GetMe { +impl Request for GetMe { + type ReturnValue = User; + fn name(&self) -> &str { "getMe" } diff --git a/src/core/requests/mod.rs b/src/core/requests/mod.rs index 1cb3c024..f29c294e 100644 --- a/src/core/requests/mod.rs +++ b/src/core/requests/mod.rs @@ -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 { +/// `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; diff --git a/src/core/requests/send_message.rs b/src/core/requests/send_message.rs index 08b67dba..217dcfc9 100644 --- a/src/core/requests/send_message.rs +++ b/src/core/requests/send_message.rs @@ -21,7 +21,9 @@ pub struct SendMessage { reply_markup: Option<()>, // TODO: ReplyMarkup enum } -impl Request for SendMessage { +impl Request for SendMessage { + type ReturnValue = Message; + fn name(&self) -> &str { "getMe" }