use core::fmt::Display;
pub trait Api {
type Error: Display + From<crate::Error>;
type Id: ApiId;
#[inline]
fn after_sending(&mut self) -> impl Future<Output = Result<(), Self::Error>> {
async { Ok(()) }
}
#[inline]
fn before_sending(&mut self) -> impl Future<Output = Result<(), Self::Error>> {
async { Ok(()) }
}
}
impl Api for () {
type Error = crate::Error;
type Id = ();
}
impl<T> Api for &mut T
where
T: Api,
{
type Error = T::Error;
type Id = T::Id;
#[inline]
async fn after_sending(&mut self) -> Result<(), Self::Error> {
(**self).after_sending().await
}
#[inline]
async fn before_sending(&mut self) -> Result<(), Self::Error> {
(**self).before_sending().await
}
}
pub trait ApiId {
type Api<T>: Api;
}
impl ApiId for () {
type Api<T> = ();
}