mirror of
https://github.com/teloxide/teloxide.git
synced 2025-03-13 11:18:17 +01:00
implement HasPayload
in terms of As{Ref,Mut}
This commit is contained in:
parent
76d47276f6
commit
c773ce7aff
2 changed files with 8 additions and 12 deletions
|
@ -18,15 +18,19 @@ use crate::requests::Payload;
|
|||
/// [`BorrowMut`]: std::borrow::BorrowMut
|
||||
/// [`Payload`]: crate::requests::Payload
|
||||
/// [output]: HasPayload::Payload
|
||||
pub trait HasPayload {
|
||||
pub trait HasPayload: AsMut<<Self as HasPayload>::Payload> + AsRef<<Self as HasPayload>::Payload> {
|
||||
/// Type of the payload contained.
|
||||
type Payload: Payload;
|
||||
|
||||
/// Gain mutable access to the underlying payload.
|
||||
fn payload_mut(&mut self) -> &mut Self::Payload;
|
||||
fn payload_mut(&mut self) -> &mut Self::Payload {
|
||||
self.as_mut()
|
||||
}
|
||||
|
||||
/// Gain immutable access to the underlying payload.
|
||||
fn payload_ref(&self) -> &Self::Payload;
|
||||
fn payload_ref(&self) -> &Self::Payload {
|
||||
self.as_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<P> HasPayload for P
|
||||
|
@ -34,12 +38,4 @@ where
|
|||
P: Payload,
|
||||
{
|
||||
type Payload = Self;
|
||||
|
||||
fn payload_mut(&mut self) -> &mut Self::Payload {
|
||||
self
|
||||
}
|
||||
|
||||
fn payload_ref(&self) -> &Self::Payload {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
pub trait Payload: AsMut<Self> + AsRef<Self> {
|
||||
/// 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