mod pkg_with_helper;
mod pkgs_aux;
use crate::{
client_api_framework::Api,
codec::{DecodeSeq, Encode, GenericCodec},
collection::Vector,
};
pub use pkg_with_helper::*;
pub use pkgs_aux::*;
pub trait Package<A, DRSR, T, TP>
where
A: Api,
for<'drsr> Self::ExternalRequestContent: Encode<GenericCodec<&'drsr mut DRSR, &'drsr mut DRSR>>,
for<'de, 'drsr> Self::ExternalResponseContent<'de>:
DecodeSeq<'de, GenericCodec<&'drsr mut DRSR, &'drsr mut DRSR>>,
{
type ExternalRequestContent;
type ExternalResponseContent<'de>;
type PackageParams;
#[inline]
fn after_sending(
&mut self,
_: (&mut A, &mut Vector<u8>, &mut DRSR),
_: (&mut T, &mut TP),
) -> impl Future<Output = Result<(), A::Error>> {
async { Ok(()) }
}
#[inline]
fn before_sending(
&mut self,
_: (&mut A, &mut Vector<u8>, &mut DRSR),
_: (&mut T, &mut TP),
) -> impl Future<Output = Result<(), A::Error>> {
async { Ok(()) }
}
fn ext_req_content(&self) -> &Self::ExternalRequestContent;
fn ext_req_content_mut(&mut self) -> &mut Self::ExternalRequestContent;
fn pkg_params(&self) -> &Self::PackageParams;
fn pkg_params_mut(&mut self) -> &mut Self::PackageParams;
}
impl<A, DRSR, T, TP> Package<A, DRSR, T, TP> for ()
where
A: Api,
{
type ExternalRequestContent = ();
type ExternalResponseContent<'de> = ();
type PackageParams = ();
#[inline]
fn ext_req_content(&self) -> &Self::ExternalRequestContent {
&()
}
#[inline]
fn ext_req_content_mut(&mut self) -> &mut Self::ExternalRequestContent {
self
}
#[inline]
fn pkg_params(&self) -> &Self::PackageParams {
self
}
#[inline]
fn pkg_params_mut(&mut self) -> &mut Self::PackageParams {
self
}
}
impl<A, DRSR, P, T, TP> Package<A, DRSR, T, TP> for &mut P
where
A: Api,
P: Package<A, DRSR, T, TP>,
{
type ExternalRequestContent = P::ExternalRequestContent;
type ExternalResponseContent<'de> = P::ExternalResponseContent<'de>;
type PackageParams = P::PackageParams;
#[inline]
async fn after_sending(
&mut self,
(api, bytes, drsr): (&mut A, &mut Vector<u8>, &mut DRSR),
(trans, trans_params): (&mut T, &mut TP),
) -> Result<(), A::Error> {
(**self).after_sending((api, bytes, drsr), (trans, trans_params)).await
}
#[inline]
async fn before_sending(
&mut self,
(api, bytes, drsr): (&mut A, &mut Vector<u8>, &mut DRSR),
(trans, trans_params): (&mut T, &mut TP),
) -> Result<(), A::Error> {
(**self).before_sending((api, bytes, drsr), (trans, trans_params)).await
}
#[inline]
fn ext_req_content(&self) -> &Self::ExternalRequestContent {
(**self).ext_req_content()
}
#[inline]
fn ext_req_content_mut(&mut self) -> &mut Self::ExternalRequestContent {
(**self).ext_req_content_mut()
}
#[inline]
fn pkg_params(&self) -> &Self::PackageParams {
(**self).pkg_params()
}
#[inline]
fn pkg_params_mut(&mut self) -> &mut Self::PackageParams {
(**self).pkg_params_mut()
}
}