Add some docs

This commit is contained in:
Waffle 2019-11-05 00:47:31 +03:00
parent 86f9e9911c
commit e2922199d4
5 changed files with 32 additions and 1 deletions

View file

@ -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(),

View file

@ -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(),

View file

@ -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;
}

View file

@ -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(),

View file

@ -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(),