Add requests::respond

This commit is contained in:
Temirkhan Myrzamadi 2020-08-02 13:08:43 +06:00
parent 3703f2dff6
commit 05e32336fa
4 changed files with 8 additions and 3 deletions

View file

@ -103,7 +103,7 @@ async fn main() {
teloxide::repl(bot, |message| async move { teloxide::repl(bot, |message| async move {
message.answer_dice().send().await?; message.answer_dice().send().await?;
ResponseResult::<()>::Ok(()) respond(())
}) })
.await; .await;
} }

View file

@ -15,7 +15,7 @@ async fn run() {
teloxide::repl(bot, |message| async move { teloxide::repl(bot, |message| async move {
message.answer_dice().send().await?; message.answer_dice().send().await?;
ResponseResult::<()>::Ok(()) respond(())
}) })
.await; .await;
} }

View file

@ -9,7 +9,7 @@ pub use crate::{
Dispatcher, DispatcherHandlerRx, DispatcherHandlerRxExt, UpdateWithCx, Dispatcher, DispatcherHandlerRx, DispatcherHandlerRxExt, UpdateWithCx,
}, },
error_handlers::{LoggingErrorHandler, OnError}, error_handlers::{LoggingErrorHandler, OnError},
requests::{Request, ResponseResult}, requests::{respond, Request, ResponseResult},
types::{Message, Update}, types::{Message, Update},
Bot, RequestError, Bot, RequestError,
}; };

View file

@ -9,6 +9,11 @@ pub use all::*;
/// A type that is returned after making a request to Telegram. /// A type that is returned after making a request to Telegram.
pub type ResponseResult<T> = Result<T, crate::RequestError>; pub type ResponseResult<T> = Result<T, crate::RequestError>;
/// A shortcut for `ResponseResult::Ok(val)`.
pub fn respond<T>(val: T) -> ResponseResult<T> {
ResponseResult::Ok(val)
}
/// Designates an API request. /// Designates an API request.
#[async_trait::async_trait] #[async_trait::async_trait]
pub trait Request { pub trait Request {