mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-14 11:44:04 +01:00
Move modules to files
This commit is contained in:
parent
7868d9c832
commit
b788da0608
4 changed files with 95 additions and 87 deletions
30
src/requests/json.rs
Normal file
30
src/requests/json.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
use crate::{Bot, network};
|
||||
use super::{ResponseResult, Method};
|
||||
|
||||
pub trait Payload: Serialize + Method {}
|
||||
|
||||
pub struct Request<'b, P> {
|
||||
bot: &'b Bot,
|
||||
pub(crate) payload: P,
|
||||
}
|
||||
|
||||
impl<'b, P> Request<'b, P>
|
||||
where
|
||||
P: Payload,
|
||||
P::Output: DeserializeOwned,
|
||||
{
|
||||
pub fn new(bot: &'b Bot, payload: P) -> Self {
|
||||
Self { bot, payload }
|
||||
}
|
||||
|
||||
pub async fn send(&self) -> ResponseResult<P::Output> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
P::METHOD,
|
||||
&self.payload,
|
||||
).await
|
||||
}
|
||||
}
|
|
@ -115,90 +115,6 @@ pub trait Method {
|
|||
const METHOD: &'static str;
|
||||
}
|
||||
|
||||
pub mod json {
|
||||
use serde::{de::DeserializeOwned, Serialize};
|
||||
|
||||
use crate::{Bot, network};
|
||||
use super::{ResponseResult, Method};
|
||||
|
||||
pub trait Payload: Serialize + Method {}
|
||||
|
||||
pub struct Request<'b, P> {
|
||||
pub(crate) bot: &'b Bot,
|
||||
pub(crate) payload: P,
|
||||
}
|
||||
|
||||
impl<P> Request<'_, P>
|
||||
where
|
||||
P: Payload,
|
||||
P::Output: DeserializeOwned,
|
||||
{
|
||||
pub async fn send(&self) -> ResponseResult<P::Output> {
|
||||
network::request_json(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
P::METHOD,
|
||||
&self.payload,
|
||||
).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod multipart {
|
||||
use serde::de::DeserializeOwned;
|
||||
use reqwest::multipart;
|
||||
|
||||
use crate::{Bot, network};
|
||||
use super::{ResponseResult, Method};
|
||||
|
||||
pub trait Payload: Method {
|
||||
fn payload(&self) -> multipart::Form;
|
||||
}
|
||||
|
||||
pub struct Request<'b, P> {
|
||||
pub(crate) bot: &'b Bot,
|
||||
pub(crate) payload: P,
|
||||
}
|
||||
|
||||
impl<P> Request<'_, P>
|
||||
where
|
||||
P: Payload,
|
||||
P::Output: DeserializeOwned,
|
||||
{
|
||||
pub async fn send(&self) -> ResponseResult<P::Output> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
P::METHOD,
|
||||
self.payload.payload(),
|
||||
).await
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod simple {
|
||||
use serde::de::DeserializeOwned;
|
||||
use reqwest::multipart;
|
||||
|
||||
use crate::{Bot, network};
|
||||
use super::{ResponseResult, Method};
|
||||
|
||||
pub struct Request<'b, M> {
|
||||
pub(crate) bot: &'b Bot,
|
||||
marker: std::marker::PhantomData<M>,
|
||||
}
|
||||
|
||||
impl<M> Request<'_, M>
|
||||
where
|
||||
M: Method,
|
||||
M::Output: DeserializeOwned,
|
||||
{
|
||||
pub async fn send(&self) -> ResponseResult<M::Output> {
|
||||
network::request_simple(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
M::METHOD,
|
||||
).await
|
||||
}
|
||||
}
|
||||
}
|
||||
pub mod json;
|
||||
pub mod multipart;
|
||||
pub mod simple;
|
||||
|
|
33
src/requests/multipart.rs
Normal file
33
src/requests/multipart.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use serde::de::DeserializeOwned;
|
||||
use reqwest::multipart;
|
||||
|
||||
use crate::{Bot, network};
|
||||
use super::{ResponseResult, Method};
|
||||
|
||||
pub trait Payload: Method {
|
||||
fn payload(&self) -> multipart::Form;
|
||||
}
|
||||
|
||||
pub struct Request<'b, P> {
|
||||
bot: &'b Bot,
|
||||
pub(crate) payload: P,
|
||||
}
|
||||
|
||||
impl<'b, P> Request<'b, P>
|
||||
where
|
||||
P: Payload,
|
||||
P::Output: DeserializeOwned,
|
||||
{
|
||||
pub fn new(bot: &'b Bot, payload: P) -> Self {
|
||||
Self { bot, payload }
|
||||
}
|
||||
|
||||
pub async fn send(&self) -> ResponseResult<P::Output> {
|
||||
network::request_multipart(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
P::METHOD,
|
||||
self.payload.payload(),
|
||||
).await
|
||||
}
|
||||
}
|
29
src/requests/simple.rs
Normal file
29
src/requests/simple.rs
Normal file
|
@ -0,0 +1,29 @@
|
|||
use serde::de::DeserializeOwned;
|
||||
use reqwest::multipart;
|
||||
|
||||
use crate::{Bot, network};
|
||||
use super::{ResponseResult, Method};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
pub struct Request<'b, M> {
|
||||
bot: &'b Bot,
|
||||
marker: PhantomData<M>,
|
||||
}
|
||||
|
||||
impl<'b, M> Request<'b, M>
|
||||
where
|
||||
M: Method,
|
||||
M::Output: DeserializeOwned,
|
||||
{
|
||||
pub fn new(bot: &'b Bot) -> Self {
|
||||
Self { bot, marker: PhantomData }
|
||||
}
|
||||
|
||||
pub async fn send(&self) -> ResponseResult<M::Output> {
|
||||
network::request_simple(
|
||||
self.bot.client(),
|
||||
self.bot.token(),
|
||||
M::METHOD,
|
||||
).await
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue