mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-08 03:22:06 +01:00
Merge pull request #127 from teloxide/must_use_requests
Add `#[must_use]` attrs to payload setters, request wrappers and send* methods
This commit is contained in:
commit
839181bffd
9 changed files with 15 additions and 6 deletions
|
@ -116,6 +116,7 @@ download_forward! {
|
|||
{ this => this.inner() }
|
||||
}
|
||||
|
||||
#[must_use = "Futures are lazy and do nothing unless polled or awaited"]
|
||||
#[pin_project::pin_project]
|
||||
pub struct AutoRequest<R: Request>(#[pin] Inner<R>);
|
||||
|
||||
|
|
|
@ -123,6 +123,7 @@ download_forward! {
|
|||
{ this => this.inner() }
|
||||
}
|
||||
|
||||
#[must_use = "Requests are lazy and do nothing unless sent"]
|
||||
pub struct CachedMeRequest<R: Request<Payload = GetMe>>(Inner<R>, GetMe);
|
||||
|
||||
enum Inner<R: Request<Payload = GetMe>> {
|
||||
|
|
|
@ -35,6 +35,7 @@ impl<'a, E> ErasedRequester<'a, E> {
|
|||
}
|
||||
|
||||
/// [`Request`] with erased type.
|
||||
#[must_use = "Requests are lazy and do nothing unless sent"]
|
||||
pub struct ErasedRequest<'a, T, E> {
|
||||
inner: Box<dyn ErasableRequest<'a, Payload = T, Err = E> + 'a>,
|
||||
}
|
||||
|
|
|
@ -663,6 +663,7 @@ impl From<&ChatId> for ChatIdHash {
|
|||
}
|
||||
}
|
||||
|
||||
#[must_use = "Requests are lazy and do nothing unless sent"]
|
||||
pub struct ThrottlingRequest<R: HasPayload> {
|
||||
request: R,
|
||||
chat_id: fn(&R::Payload) -> ChatIdHash,
|
||||
|
|
|
@ -141,6 +141,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
#[must_use = "Requests are lazy and do nothing unless sent"]
|
||||
pub struct TraceRequest<R> {
|
||||
inner: R,
|
||||
settings: Settings,
|
||||
|
|
|
@ -255,6 +255,7 @@ macro_rules! impl_payload {
|
|||
") field."
|
||||
)]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
#[must_use = "Payloads and requests do nothing unless sent"]
|
||||
fn $field<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<$FTy>,
|
||||
|
@ -276,6 +277,7 @@ macro_rules! impl_payload {
|
|||
") field."
|
||||
)]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
#[must_use = "Payloads and requests do nothing unless sent"]
|
||||
fn $field<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: ::core::iter::IntoIterator<Item = <$FTy as ::core::iter::IntoIterator>::Item>,
|
||||
|
@ -297,6 +299,7 @@ macro_rules! impl_payload {
|
|||
") field."
|
||||
)]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
#[must_use = "Payloads and requests do nothing unless sent"]
|
||||
fn $field(mut self, value: $FTy) -> Self {
|
||||
self.payload_mut().$field = Some(value);
|
||||
self
|
||||
|
@ -315,6 +318,7 @@ macro_rules! impl_payload {
|
|||
") field."
|
||||
)]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
#[must_use = "Payloads and requests do nothing unless sent"]
|
||||
fn $field<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: Into<$FTy>,
|
||||
|
@ -336,6 +340,7 @@ macro_rules! impl_payload {
|
|||
") field."
|
||||
)]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
#[must_use = "Payloads and requests do nothing unless sent"]
|
||||
fn $field<T>(mut self, value: T) -> Self
|
||||
where
|
||||
T: ::core::iter::IntoIterator<Item = <$FTy as ::core::iter::IntoIterator>::Item>,
|
||||
|
@ -357,6 +362,7 @@ macro_rules! impl_payload {
|
|||
") field."
|
||||
)]
|
||||
#[allow(clippy::wrong_self_convention)]
|
||||
#[must_use = "Payloads and requests do nothing unless sent"]
|
||||
fn $field(mut self, value: $FTy) -> Self {
|
||||
self.payload_mut().$field = value;
|
||||
self
|
||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
|||
/// A ready-to-send Telegram request whose payload is sent using [JSON].
|
||||
///
|
||||
/// [JSON]: https://core.telegram.org/bots/api#making-requests
|
||||
#[must_use = "requests do nothing until sent"]
|
||||
#[must_use = "Requests are lazy and do nothing unless sent"]
|
||||
pub struct JsonRequest<P> {
|
||||
bot: Bot,
|
||||
payload: P,
|
||||
|
|
|
@ -10,7 +10,7 @@ use crate::{
|
|||
/// [multipart/form-data].
|
||||
///
|
||||
/// [multipart/form-data]: https://core.telegram.org/bots/api#making-requests
|
||||
#[must_use = "requests do nothing until sent"]
|
||||
#[must_use = "Requests are lazy and do nothing unless sent"]
|
||||
pub struct MultipartRequest<P> {
|
||||
bot: Bot,
|
||||
payload: P,
|
||||
|
|
|
@ -59,6 +59,7 @@ pub trait Request: HasPayload {
|
|||
/// let _: Me = request.send().await.unwrap();
|
||||
/// # };
|
||||
/// ```
|
||||
#[must_use = "Futures are lazy and do nothing unless polled or awaited"]
|
||||
fn send(self) -> Self::Send;
|
||||
|
||||
/// Send this request by reference.
|
||||
|
@ -86,13 +87,10 @@ pub trait Request: HasPayload {
|
|||
/// }
|
||||
/// # };
|
||||
/// ```
|
||||
#[must_use = "Futures are lazy and do nothing unless polled or awaited"]
|
||||
fn send_ref(&self) -> Self::SendRef;
|
||||
|
||||
#[cfg(feature = "erased")]
|
||||
#[cfg_attr(
|
||||
all(any(docsrs, dep_docsrs), feature = "nightly"),
|
||||
doc(cfg(feature = "erased"))
|
||||
)]
|
||||
fn erase<'a>(self) -> crate::adaptors::erased::ErasedRequest<'a, Self::Payload, Self::Err>
|
||||
where
|
||||
Self: Sized + 'a,
|
||||
|
|
Loading…
Reference in a new issue