use core::pin::Pin;
use alloc::boxed::Box;
pub trait GetFut {
type Input;
type Output;
fn get_fut<'a>(self, input: &'a mut Self::Input) -> impl 'a + Future<Output = Self::Output>;
}
pub trait ApplyGetFut: GetFut {
fn apply_to(self, val: Self::Input) -> Pin<Box<impl Future<Output = Self::Output>>>;
}
impl<G: GetFut> ApplyGetFut for G {
fn apply_to(self, val: Self::Input) -> Pin<Box<impl Future<Output = Self::Output>>> {
crate::make(val, self)
}
}
pub trait TryGetFut {
type Input;
type Output;
type Aux;
type Error;
fn try_get_fut<'a>(
self,
input: &'a mut Self::Input,
) -> Result<(impl 'a + Future<Output = Self::Output>, Self::Aux), Self::Error>;
}
pub trait TryApplyGetFut: TryGetFut {
fn apply_to(
self,
val: Self::Input,
) -> Result<(Pin<Box<impl Future<Output = Self::Output>>>, Self::Aux), (Self::Input, Self::Error)>;
}
impl<G: TryGetFut> TryApplyGetFut for G {
fn apply_to(
self,
val: Self::Input,
) -> Result<(Pin<Box<impl Future<Output = Self::Output>>>, Self::Aux), (Self::Input, Self::Error)>
{
crate::try_make(val, self)
}
}
#[cfg(feature = "async")]
mod async_feature {
use alloc::boxed::Box;
use core::pin::Pin;
use crate::{AsyncSendTryOutput, AsyncTryOutput};
pub trait AsyncTryGetFut<'a>: 'a {
type Input: 'a;
type Output: 'a;
type Aux: 'a;
type Error: 'a;
#[allow(async_fn_in_trait)]
async fn async_try_get_fut<'b>(
self,
input: &'b mut Self::Input,
) -> Result<(impl 'b + Future<Output = Self::Output>, Self::Aux), Self::Error>;
}
pub trait AsyncTryApplyGetFut<'a>: AsyncTryGetFut<'a> {
#[allow(async_fn_in_trait)]
async fn apply_to(self, val: Self::Input) -> AsyncTryOutput<'a, Self>;
}
impl<'a, G: AsyncTryGetFut<'a>> AsyncTryApplyGetFut<'a> for G {
async fn apply_to(self, val: Self::Input) -> AsyncTryOutput<'a, Self> {
crate::AsyncTry::new(val, self).await
}
}
pub trait AsyncSendTryGetFut<'a>: 'a + Send {
type Input: 'a + Sync + Send;
type Output: 'a + Send;
type Aux: 'a + Send;
type Error: 'a + Send;
fn async_send_try_get_fut<'b>(
self,
input: &'b mut Self::Input,
) -> Pin<
Box<
dyn 'b
+ Send
+ Future<
Output = Result<
(
Pin<Box<dyn 'b + Send + Future<Output = Self::Output>>>,
Self::Aux,
),
Self::Error,
>,
>,
>,
>;
}
pub trait AsyncSendTryApplyGetFut<'a>: AsyncSendTryGetFut<'a> {
#[allow(async_fn_in_trait)]
async fn apply_to(self, val: Self::Input) -> AsyncSendTryOutput<'a, Self>;
}
impl<'a, G: AsyncSendTryGetFut<'a>> AsyncSendTryApplyGetFut<'a> for G {
async fn apply_to(self, val: Self::Input) -> AsyncSendTryOutput<'a, Self> {
crate::AsyncSendTry::new(val, self).await
}
}
}
#[cfg(feature = "async")]
pub use async_feature::*;