mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-09 11:43:57 +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() }
|
{ this => this.inner() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use = "Futures are lazy and do nothing unless polled or awaited"]
|
||||||
#[pin_project::pin_project]
|
#[pin_project::pin_project]
|
||||||
pub struct AutoRequest<R: Request>(#[pin] Inner<R>);
|
pub struct AutoRequest<R: Request>(#[pin] Inner<R>);
|
||||||
|
|
||||||
|
|
|
@ -123,6 +123,7 @@ download_forward! {
|
||||||
{ this => this.inner() }
|
{ this => this.inner() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[must_use = "Requests are lazy and do nothing unless sent"]
|
||||||
pub struct CachedMeRequest<R: Request<Payload = GetMe>>(Inner<R>, GetMe);
|
pub struct CachedMeRequest<R: Request<Payload = GetMe>>(Inner<R>, GetMe);
|
||||||
|
|
||||||
enum Inner<R: Request<Payload = GetMe>> {
|
enum Inner<R: Request<Payload = GetMe>> {
|
||||||
|
|
|
@ -35,6 +35,7 @@ impl<'a, E> ErasedRequester<'a, E> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// [`Request`] with erased type.
|
/// [`Request`] with erased type.
|
||||||
|
#[must_use = "Requests are lazy and do nothing unless sent"]
|
||||||
pub struct ErasedRequest<'a, T, E> {
|
pub struct ErasedRequest<'a, T, E> {
|
||||||
inner: Box<dyn ErasableRequest<'a, Payload = T, Err = E> + 'a>,
|
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> {
|
pub struct ThrottlingRequest<R: HasPayload> {
|
||||||
request: R,
|
request: R,
|
||||||
chat_id: fn(&R::Payload) -> ChatIdHash,
|
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> {
|
pub struct TraceRequest<R> {
|
||||||
inner: R,
|
inner: R,
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
|
|
|
@ -255,6 +255,7 @@ macro_rules! impl_payload {
|
||||||
") field."
|
") field."
|
||||||
)]
|
)]
|
||||||
#[allow(clippy::wrong_self_convention)]
|
#[allow(clippy::wrong_self_convention)]
|
||||||
|
#[must_use = "Payloads and requests do nothing unless sent"]
|
||||||
fn $field<T>(mut self, value: T) -> Self
|
fn $field<T>(mut self, value: T) -> Self
|
||||||
where
|
where
|
||||||
T: Into<$FTy>,
|
T: Into<$FTy>,
|
||||||
|
@ -276,6 +277,7 @@ macro_rules! impl_payload {
|
||||||
") field."
|
") field."
|
||||||
)]
|
)]
|
||||||
#[allow(clippy::wrong_self_convention)]
|
#[allow(clippy::wrong_self_convention)]
|
||||||
|
#[must_use = "Payloads and requests do nothing unless sent"]
|
||||||
fn $field<T>(mut self, value: T) -> Self
|
fn $field<T>(mut self, value: T) -> Self
|
||||||
where
|
where
|
||||||
T: ::core::iter::IntoIterator<Item = <$FTy as ::core::iter::IntoIterator>::Item>,
|
T: ::core::iter::IntoIterator<Item = <$FTy as ::core::iter::IntoIterator>::Item>,
|
||||||
|
@ -297,6 +299,7 @@ macro_rules! impl_payload {
|
||||||
") field."
|
") field."
|
||||||
)]
|
)]
|
||||||
#[allow(clippy::wrong_self_convention)]
|
#[allow(clippy::wrong_self_convention)]
|
||||||
|
#[must_use = "Payloads and requests do nothing unless sent"]
|
||||||
fn $field(mut self, value: $FTy) -> Self {
|
fn $field(mut self, value: $FTy) -> Self {
|
||||||
self.payload_mut().$field = Some(value);
|
self.payload_mut().$field = Some(value);
|
||||||
self
|
self
|
||||||
|
@ -315,6 +318,7 @@ macro_rules! impl_payload {
|
||||||
") field."
|
") field."
|
||||||
)]
|
)]
|
||||||
#[allow(clippy::wrong_self_convention)]
|
#[allow(clippy::wrong_self_convention)]
|
||||||
|
#[must_use = "Payloads and requests do nothing unless sent"]
|
||||||
fn $field<T>(mut self, value: T) -> Self
|
fn $field<T>(mut self, value: T) -> Self
|
||||||
where
|
where
|
||||||
T: Into<$FTy>,
|
T: Into<$FTy>,
|
||||||
|
@ -336,6 +340,7 @@ macro_rules! impl_payload {
|
||||||
") field."
|
") field."
|
||||||
)]
|
)]
|
||||||
#[allow(clippy::wrong_self_convention)]
|
#[allow(clippy::wrong_self_convention)]
|
||||||
|
#[must_use = "Payloads and requests do nothing unless sent"]
|
||||||
fn $field<T>(mut self, value: T) -> Self
|
fn $field<T>(mut self, value: T) -> Self
|
||||||
where
|
where
|
||||||
T: ::core::iter::IntoIterator<Item = <$FTy as ::core::iter::IntoIterator>::Item>,
|
T: ::core::iter::IntoIterator<Item = <$FTy as ::core::iter::IntoIterator>::Item>,
|
||||||
|
@ -357,6 +362,7 @@ macro_rules! impl_payload {
|
||||||
") field."
|
") field."
|
||||||
)]
|
)]
|
||||||
#[allow(clippy::wrong_self_convention)]
|
#[allow(clippy::wrong_self_convention)]
|
||||||
|
#[must_use = "Payloads and requests do nothing unless sent"]
|
||||||
fn $field(mut self, value: $FTy) -> Self {
|
fn $field(mut self, value: $FTy) -> Self {
|
||||||
self.payload_mut().$field = value;
|
self.payload_mut().$field = value;
|
||||||
self
|
self
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::{
|
||||||
/// A ready-to-send Telegram request whose payload is sent using [JSON].
|
/// A ready-to-send Telegram request whose payload is sent using [JSON].
|
||||||
///
|
///
|
||||||
/// [JSON]: https://core.telegram.org/bots/api#making-requests
|
/// [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> {
|
pub struct JsonRequest<P> {
|
||||||
bot: Bot,
|
bot: Bot,
|
||||||
payload: P,
|
payload: P,
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::{
|
||||||
/// [multipart/form-data].
|
/// [multipart/form-data].
|
||||||
///
|
///
|
||||||
/// [multipart/form-data]: https://core.telegram.org/bots/api#making-requests
|
/// [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> {
|
pub struct MultipartRequest<P> {
|
||||||
bot: Bot,
|
bot: Bot,
|
||||||
payload: P,
|
payload: P,
|
||||||
|
|
|
@ -59,6 +59,7 @@ pub trait Request: HasPayload {
|
||||||
/// let _: Me = request.send().await.unwrap();
|
/// let _: Me = request.send().await.unwrap();
|
||||||
/// # };
|
/// # };
|
||||||
/// ```
|
/// ```
|
||||||
|
#[must_use = "Futures are lazy and do nothing unless polled or awaited"]
|
||||||
fn send(self) -> Self::Send;
|
fn send(self) -> Self::Send;
|
||||||
|
|
||||||
/// Send this request by reference.
|
/// 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;
|
fn send_ref(&self) -> Self::SendRef;
|
||||||
|
|
||||||
#[cfg(feature = "erased")]
|
#[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>
|
fn erase<'a>(self) -> crate::adaptors::erased::ErasedRequest<'a, Self::Payload, Self::Err>
|
||||||
where
|
where
|
||||||
Self: Sized + 'a,
|
Self: Sized + 'a,
|
||||||
|
|
Loading…
Reference in a new issue