Make the trait bounds in Request{,er} stricter

This commit is contained in:
Waffle 2020-10-20 12:17:07 +03:00
parent a2d87fe1fa
commit e54f45ceab
7 changed files with 31 additions and 11 deletions

View file

@ -1705,6 +1705,8 @@ impl Bot {
}
impl Requester for Bot {
type Err = crate::errors::RequestError;
type GetMe = JsonRequest<payloads::GetMe>;
fn get_me(&self) -> JsonRequest<payloads::GetMe> {

View file

@ -63,6 +63,8 @@ impl<B> AutoSend<B> {
}
impl<B: Requester> Requester for AutoSend<B> {
type Err = B::Err;
type GetMe = AutoRequest<B::GetMe>;
fn get_me(&self) -> Self::GetMe {

View file

@ -54,7 +54,12 @@ impl<B> CacheMe<B> {
}
}
impl<B: Requester> Requester for CacheMe<B> {
impl<B> Requester for CacheMe<B>
where
B: Requester,
{
type Err = B::Err;
type GetMe = CachedMeRequest<B::GetMe>;
fn get_me(&self) -> Self::GetMe {
@ -85,7 +90,10 @@ enum Inner<R: Request<Payload = GetMe>> {
Pending(R, Arc<OnceCell<User>>),
}
impl<R: Request<Payload = GetMe>> Request for CachedMeRequest<R> {
impl<R> Request for CachedMeRequest<R>
where
R: Request<Payload = GetMe>,
{
type Err = R::Err;
type Send = Send<R>;
type SendRef = SendRef<R>;

View file

@ -346,7 +346,12 @@ impl<B> Throttle<B> {
}
}
impl<B: Requester> Requester for Throttle<B> {
impl<B: Requester> Requester for Throttle<B>
where
B::SendMessage: Send,
{
type Err = B::Err;
type GetMe = B::GetMe;
fn get_me(&self) -> Self::GetMe {
@ -412,8 +417,9 @@ impl<R: HasPayload> HasPayload for ThrottlingRequest<R> {
}
}
impl<R: Request> Request for ThrottlingRequest<R>
impl<R> Request for ThrottlingRequest<R>
where
R: Request + Send,
<R as HasPayload>::Payload: GetChatId,
{
type Err = R::Err;
@ -617,7 +623,7 @@ mod chan_send {
pub(super) struct ChanSend(#[pin] Inner);
#[cfg(not(feature = "nightly"))]
type Inner = Pin<Box<dyn Future<Output = Result<(), SendError<(Id, Sender<Never>)>>>>>;
type Inner = Pin<Box<dyn Future<Output = Result<(), SendError<(Id, Sender<Never>)>>> + Send>>;
#[cfg(feature = "nightly")]
type Inner = impl Future<Output = Result<(), SendError<(Id, Sender<Never>)>>>;

View file

@ -83,7 +83,7 @@ macro_rules! req_future {
#[cfg(not(feature = "nightly"))]
pub(crate) type $i<$T>
$(where $($wh)*)? = ::core::pin::Pin<Box<dyn ::core::future::Future<Output = $Out>>>;
$(where $($wh)*)? = ::core::pin::Pin<Box<dyn ::core::future::Future<Output = $Out> + ::core::marker::Send + 'static>>;
#[cfg(not(feature = "nightly"))]
pub(crate) fn def<$T>($( $arg: $ArgTy ),*) -> $i<$T>

View file

@ -22,16 +22,16 @@ pub trait Request: HasPayload {
*/
/// Type of error that may happen during sending the request to telegram.
type Err: std::error::Error;
type Err: std::error::Error + Send;
/// Type of future returned by [`send`](Request::send) method.
type Send: Future<Output = Result<Output<Self>, Self::Err>>;
type Send: Future<Output = Result<Output<Self>, Self::Err>> + Send;
/// Type of future returned by [`send_ref`](Request::send_ref) method.
///
/// NOTE: it intentionally forbids borrowing from self
// though anyway we couldn't allow borrowing without GATs :sob:
type SendRef: Future<Output = Result<Output<Self>, Self::Err>>;
type SendRef: Future<Output = Result<Output<Self>, Self::Err>> + Send;
/// Send the request.
///

View file

@ -10,12 +10,14 @@ use crate::{
/// _This trait is included in the crate's [`prelude`](crate::prelude)_.
#[cfg_attr(all(docsrs, feature = "nightly"), doc(spotlight))]
pub trait Requester {
type GetMe: Request<Payload = GetMe>;
type Err: std::error::Error + Send;
type GetMe: Request<Payload = GetMe, Err = Self::Err>;
/// For telegram documentation of the method see [`GetMe`].
fn get_me(&self) -> Self::GetMe;
type SendMessage: Request<Payload = SendMessage>;
type SendMessage: Request<Payload = SendMessage, Err = Self::Err>;
/// For telegram documentation of the method see [`SendMessage`].
fn send_message<C, T>(&self, chat_id: C, text: T) -> Self::SendMessage