mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-13 11:18:17 +01:00
remove AsMut/AsRef bounds because of a compiler bug
This commit is contained in:
parent
7d7fd89bfa
commit
f3e0005335
4 changed files with 29 additions and 31 deletions
|
@ -18,21 +18,19 @@ use crate::requests::Payload;
|
|||
/// [`BorrowMut`]: std::borrow::BorrowMut
|
||||
/// [`Payload`]: crate::requests::Payload
|
||||
/// [output]: HasPayload::Payload
|
||||
pub trait HasPayload:
|
||||
AsMut<<Self as HasPayload>::Payload> + AsRef<<Self as HasPayload>::Payload>
|
||||
pub trait HasPayload
|
||||
// FIXME(waffle):
|
||||
// we wanted to use As{Mut,Ref} here, but they doesn't work
|
||||
// because of https://github.com/rust-lang/rust/issues/77010
|
||||
{
|
||||
/// Type of the payload contained.
|
||||
type Payload: Payload;
|
||||
|
||||
/// Gain mutable access to the underlying payload.
|
||||
fn payload_mut(&mut self) -> &mut Self::Payload {
|
||||
self.as_mut()
|
||||
}
|
||||
fn payload_mut(&mut self) -> &mut Self::Payload;
|
||||
|
||||
/// Gain immutable access to the underlying payload.
|
||||
fn payload_ref(&self) -> &Self::Payload {
|
||||
self.as_ref()
|
||||
}
|
||||
fn payload_ref(&self) -> &Self::Payload;
|
||||
}
|
||||
|
||||
impl<P> HasPayload for P
|
||||
|
@ -40,4 +38,12 @@ where
|
|||
P: Payload,
|
||||
{
|
||||
type Payload = Self;
|
||||
|
||||
fn payload_mut(&mut self) -> &mut Self::Payload {
|
||||
self
|
||||
}
|
||||
|
||||
fn payload_ref(&self) -> &Self::Payload {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,31 +55,27 @@ where
|
|||
P: Payload,
|
||||
{
|
||||
type Payload = P;
|
||||
}
|
||||
|
||||
impl<P> AsRef<P> for JsonRequest<P> {
|
||||
fn as_ref(&self) -> &P {
|
||||
&self.payload
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> AsMut<P> for JsonRequest<P> {
|
||||
fn as_mut(&mut self) -> &mut P {
|
||||
fn payload_mut(&mut self) -> &mut Self::Payload {
|
||||
&mut self.payload
|
||||
}
|
||||
|
||||
fn payload_ref(&self) -> &Self::Payload {
|
||||
&self.payload
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: Payload + Serialize> core::ops::Deref for JsonRequest<P> {
|
||||
type Target = P;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.as_ref()
|
||||
self.payload_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<P: Payload + Serialize> core::ops::DerefMut for JsonRequest<P> {
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
self.as_mut()
|
||||
self.payload_mut()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,18 +55,14 @@ where
|
|||
P: Payload,
|
||||
{
|
||||
type Payload = P;
|
||||
}
|
||||
|
||||
impl<P> AsRef<P> for MultipartRequest<P> {
|
||||
fn as_ref(&self) -> &P {
|
||||
&self.payload
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> AsMut<P> for MultipartRequest<P> {
|
||||
fn as_mut(&mut self) -> &mut P {
|
||||
fn payload_mut(&mut self) -> &mut Self::Payload {
|
||||
&mut self.payload
|
||||
}
|
||||
|
||||
fn payload_ref(&self) -> &Self::Payload {
|
||||
&self.payload
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> core::ops::Deref for MultipartRequest<P>
|
||||
|
@ -78,7 +74,7 @@ where
|
|||
type Target = P;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.as_ref()
|
||||
self.payload_ref()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +85,7 @@ where
|
|||
P::Output: DeserializeOwned,
|
||||
{
|
||||
fn deref_mut(&mut self) -> &mut Self::Target {
|
||||
self.as_mut()
|
||||
self.payload_mut()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
/// This trait provides some additional information needed for sending request
|
||||
/// to the telegram.
|
||||
#[cfg_attr(all(docsrs, feature = "nightly"), doc(spotlight))]
|
||||
pub trait Payload: AsMut<Self> + AsRef<Self> {
|
||||
pub trait Payload {
|
||||
/// Return type of the telegram method.
|
||||
///
|
||||
/// Note: that should not include result wrappers (e.g. it should be simply
|
||||
|
|
Loading…
Add table
Reference in a new issue