remove AsMut/AsRef bounds because of a compiler bug

This commit is contained in:
Waffle 2020-09-22 22:48:42 +03:00
parent 7d7fd89bfa
commit f3e0005335
4 changed files with 29 additions and 31 deletions

View file

@ -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
}
}

View file

@ -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()
}
}

View file

@ -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()
}
}

View file

@ -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