mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
Add some docs
This commit is contained in:
parent
86f9e9911c
commit
e2922199d4
5 changed files with 32 additions and 1 deletions
|
@ -20,6 +20,15 @@ pub trait Payload {
|
|||
fn kind(&self) -> Kind;
|
||||
}
|
||||
|
||||
/// Dynamic ready-to-send telegram request.
|
||||
///
|
||||
/// This type is useful for storing different requests in one place, however
|
||||
/// this type has _little_ overhead, so prefer using [json], [multipart] or
|
||||
/// [simple] requests when possible.
|
||||
///
|
||||
/// [json]: crate::requests::json::Request
|
||||
/// [multipart]: crate::requests::multipart::Request
|
||||
/// [simple]: crate::requests::simple::Request
|
||||
#[must_use = "requests do nothing until sent"]
|
||||
pub struct Request<'b, P> {
|
||||
bot: &'b Bot,
|
||||
|
@ -35,6 +44,7 @@ where
|
|||
Self { bot, payload }
|
||||
}
|
||||
|
||||
/// Send request to telegram
|
||||
pub async fn send(&self) -> ResponseResult<P::Output> {
|
||||
network::request_dynamic(
|
||||
self.bot.client(),
|
||||
|
|
|
@ -5,6 +5,11 @@ use super::{ResponseResult, Method};
|
|||
|
||||
pub trait Payload: Serialize + Method {}
|
||||
|
||||
/// Ready-to-send telegram request.
|
||||
///
|
||||
/// Note: params will be sent to telegram using [`json`]
|
||||
///
|
||||
/// [`json`]: // TODO: libk to tgdoc
|
||||
#[must_use = "requests do nothing until sent"]
|
||||
pub struct Request<'b, P> {
|
||||
bot: &'b Bot,
|
||||
|
@ -20,6 +25,7 @@ where
|
|||
Self { bot, payload }
|
||||
}
|
||||
|
||||
/// Send request to telegram
|
||||
pub async fn send(&self) -> ResponseResult<P::Output> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
|
|
|
@ -96,7 +96,7 @@ mod utils;
|
|||
use async_trait::async_trait;
|
||||
use serde::de::DeserializeOwned;
|
||||
|
||||
/// A type that is returned from `Request::send_boxed`.
|
||||
/// A type that is returned when making requests to telegram
|
||||
pub type ResponseResult<T> = Result<T, crate::RequestError>;
|
||||
|
||||
///// A request that can be sent to Telegram.
|
||||
|
@ -109,9 +109,12 @@ pub type ResponseResult<T> = Result<T, crate::RequestError>;
|
|||
// async fn send_boxed(self) -> ResponseResult<Self::Output>;
|
||||
//}
|
||||
|
||||
/// Signature of telegram method.
|
||||
pub trait Method {
|
||||
/// Return-type of the method.
|
||||
type Output;
|
||||
|
||||
/// Name of the method.
|
||||
const METHOD: &'static str;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,11 @@ pub trait Payload: Method {
|
|||
fn payload(&self) -> multipart::Form;
|
||||
}
|
||||
|
||||
/// Ready-to-send telegram request.
|
||||
///
|
||||
/// Note: params will be sent to telegram using [`multipart/form-data`]
|
||||
///
|
||||
/// [`multipart/form-data`]: // TODO: libk to tgdoc
|
||||
#[must_use = "requests do nothing until sent"]
|
||||
pub struct Request<'b, P> {
|
||||
bot: &'b Bot,
|
||||
|
@ -23,6 +28,7 @@ where
|
|||
Self { bot, payload }
|
||||
}
|
||||
|
||||
/// Send request to telegram
|
||||
pub async fn send(&self) -> ResponseResult<P::Output> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
|
|
|
@ -5,6 +5,11 @@ use crate::{Bot, network};
|
|||
use super::{ResponseResult, Method};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
/// Ready-to-send telegram request without params.
|
||||
///
|
||||
/// NOTE: Currently where is only one request without params - [GetMe]
|
||||
///
|
||||
/// [GetMe]: // TODO
|
||||
#[must_use = "requests do nothing until sent"]
|
||||
pub struct Request<'b, M> {
|
||||
bot: &'b Bot,
|
||||
|
@ -20,6 +25,7 @@ where
|
|||
Self { bot, marker: PhantomData }
|
||||
}
|
||||
|
||||
/// Send request to telegram
|
||||
pub async fn send(&self) -> ResponseResult<M::Output> {
|
||||
network::request_simple(
|
||||
self.bot.client(),
|
||||
|
|
Loading…
Add table
Reference in a new issue