From e54f45ceabb9654002ce765a1a819a0122e88e27 Mon Sep 17 00:00:00 2001 From: Waffle Date: Tue, 20 Oct 2020 12:17:07 +0300 Subject: [PATCH] Make the trait bounds in Request{,er} stricter --- src/bot/api.rs | 2 ++ src/bot/auto_send.rs | 2 ++ src/bot/cache_me.rs | 12 ++++++++++-- src/bot/limits.rs | 12 +++++++++--- src/local_macros.rs | 2 +- src/requests/request.rs | 6 +++--- src/requests/requester.rs | 6 ++++-- 7 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/bot/api.rs b/src/bot/api.rs index 5e2cb0ad..e32bdbe9 100644 --- a/src/bot/api.rs +++ b/src/bot/api.rs @@ -1705,6 +1705,8 @@ impl Bot { } impl Requester for Bot { + type Err = crate::errors::RequestError; + type GetMe = JsonRequest; fn get_me(&self) -> JsonRequest { diff --git a/src/bot/auto_send.rs b/src/bot/auto_send.rs index 5f2ceb49..98e14ad2 100644 --- a/src/bot/auto_send.rs +++ b/src/bot/auto_send.rs @@ -63,6 +63,8 @@ impl AutoSend { } impl Requester for AutoSend { + type Err = B::Err; + type GetMe = AutoRequest; fn get_me(&self) -> Self::GetMe { diff --git a/src/bot/cache_me.rs b/src/bot/cache_me.rs index 8a06ebf2..b43061e4 100644 --- a/src/bot/cache_me.rs +++ b/src/bot/cache_me.rs @@ -54,7 +54,12 @@ impl CacheMe { } } -impl Requester for CacheMe { +impl Requester for CacheMe +where + B: Requester, +{ + type Err = B::Err; + type GetMe = CachedMeRequest; fn get_me(&self) -> Self::GetMe { @@ -85,7 +90,10 @@ enum Inner> { Pending(R, Arc>), } -impl> Request for CachedMeRequest { +impl Request for CachedMeRequest +where + R: Request, +{ type Err = R::Err; type Send = Send; type SendRef = SendRef; diff --git a/src/bot/limits.rs b/src/bot/limits.rs index 52f06d44..412057a9 100644 --- a/src/bot/limits.rs +++ b/src/bot/limits.rs @@ -346,7 +346,12 @@ impl Throttle { } } -impl Requester for Throttle { +impl Requester for Throttle +where + B::SendMessage: Send, +{ + type Err = B::Err; + type GetMe = B::GetMe; fn get_me(&self) -> Self::GetMe { @@ -412,8 +417,9 @@ impl HasPayload for ThrottlingRequest { } } -impl Request for ThrottlingRequest +impl Request for ThrottlingRequest where + R: Request + Send, ::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)>>>>>; + type Inner = Pin)>>> + Send>>; #[cfg(feature = "nightly")] type Inner = impl Future)>>>; diff --git a/src/local_macros.rs b/src/local_macros.rs index c2aed978..5a48a207 100644 --- a/src/local_macros.rs +++ b/src/local_macros.rs @@ -83,7 +83,7 @@ macro_rules! req_future { #[cfg(not(feature = "nightly"))] pub(crate) type $i<$T> - $(where $($wh)*)? = ::core::pin::Pin>>; + $(where $($wh)*)? = ::core::pin::Pin + ::core::marker::Send + 'static>>; #[cfg(not(feature = "nightly"))] pub(crate) fn def<$T>($( $arg: $ArgTy ),*) -> $i<$T> diff --git a/src/requests/request.rs b/src/requests/request.rs index 8722a3e2..6abb457e 100644 --- a/src/requests/request.rs +++ b/src/requests/request.rs @@ -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, Self::Err>>; + type Send: Future, 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, Self::Err>>; + type SendRef: Future, Self::Err>> + Send; /// Send the request. /// diff --git a/src/requests/requester.rs b/src/requests/requester.rs index f9f342d1..91f297af 100644 --- a/src/requests/requester.rs +++ b/src/requests/requester.rs @@ -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; + type Err: std::error::Error + Send; + + type GetMe: Request; /// For telegram documentation of the method see [`GetMe`]. fn get_me(&self) -> Self::GetMe; - type SendMessage: Request; + type SendMessage: Request; /// For telegram documentation of the method see [`SendMessage`]. fn send_message(&self, chat_id: C, text: T) -> Self::SendMessage