use crate::{
di::{Asyncify, Injectable},
Handler, HandlerDescription,
};
impl<'a, Output, Descr> Handler<'a, Output, Descr>
where
Output: 'a,
Descr: HandlerDescription,
{
#[must_use]
#[track_caller]
pub fn filter<Pred, FnArgs>(self, pred: Pred) -> Handler<'a, Output, Descr>
where
Asyncify<Pred>: Injectable<bool, FnArgs> + Send + Sync + 'a,
{
self.chain(crate::filter(pred))
}
#[must_use]
#[track_caller]
pub fn filter_async<Pred, FnArgs>(self, pred: Pred) -> Handler<'a, Output, Descr>
where
Pred: Injectable<bool, FnArgs> + Send + Sync + 'a,
{
self.chain(crate::filter_async(pred))
}
#[must_use]
#[track_caller]
pub fn filter_map<Proj, NewType, Args>(self, proj: Proj) -> Handler<'a, Output, Descr>
where
Asyncify<Proj>: Injectable<Option<NewType>, Args> + Send + Sync + 'a,
NewType: Send + Sync + 'static,
{
self.chain(crate::filter_map(proj))
}
#[must_use]
#[track_caller]
pub fn filter_map_async<Proj, NewType, Args>(self, proj: Proj) -> Handler<'a, Output, Descr>
where
Proj: Injectable<Option<NewType>, Args> + Send + Sync + 'a,
NewType: Send + Sync + 'static,
{
self.chain(crate::filter_map_async(proj))
}
#[must_use]
#[track_caller]
pub fn map<Proj, NewType, Args>(self, proj: Proj) -> Handler<'a, Output, Descr>
where
Asyncify<Proj>: Injectable<NewType, Args> + Send + Sync + 'a,
NewType: Send + Sync + 'static,
{
self.chain(crate::map(proj))
}
#[must_use]
#[track_caller]
pub fn map_async<Proj, NewType, Args>(self, proj: Proj) -> Handler<'a, Output, Descr>
where
Proj: Injectable<NewType, Args> + Send + Sync + 'a,
NewType: Send + Sync + 'static,
{
self.chain(crate::map_async(proj))
}
#[must_use]
#[track_caller]
pub fn inspect<F, Args>(self, f: F) -> Handler<'a, Output, Descr>
where
Asyncify<F>: Injectable<(), Args> + Send + Sync + 'a,
{
self.chain(crate::inspect(f))
}
#[must_use]
#[track_caller]
pub fn inspect_async<F, Args>(self, f: F) -> Handler<'a, Output, Descr>
where
F: Injectable<(), Args> + Send + Sync + 'a,
{
self.chain(crate::inspect_async(f))
}
#[must_use]
#[track_caller]
pub fn endpoint<F, FnArgs>(self, f: F) -> Handler<'a, Output, Descr>
where
F: Injectable<Output, FnArgs> + Send + Sync + 'a,
Output: 'static,
{
self.chain(crate::endpoint(f))
}
}
#[cfg(test)]
mod tests {
use std::ops::ControlFlow;
use crate::{deps, help_inference};
#[tokio::test]
async fn test_methods() {
let value = 42;
let _: ControlFlow<(), _> =
help_inference(crate::entry()).filter(|| true).dispatch(deps![value]).await;
let _: ControlFlow<(), _> = help_inference(crate::entry())
.filter_async(|| async { true })
.dispatch(deps![value])
.await;
let _: ControlFlow<(), _> =
help_inference(crate::entry()).filter_map(|| Some("abc")).dispatch(deps![value]).await;
let _: ControlFlow<(), _> = help_inference(crate::entry())
.filter_map_async(|| async { Some("abc") })
.dispatch(deps![value])
.await;
let _: ControlFlow<(), _> =
help_inference(crate::entry()).map(|| "abc").dispatch(deps![value]).await;
let _: ControlFlow<(), _> = help_inference(crate::entry())
.map_async(|| async { "abc" })
.dispatch(deps![value])
.await;
let _: ControlFlow<(), _> =
help_inference(crate::entry()).inspect(|| {}).dispatch(deps![value]).await;
let _: ControlFlow<(), _> =
help_inference(crate::entry()).inspect_async(|| async {}).dispatch(deps![value]).await;
let _: ControlFlow<(), _> =
help_inference(crate::entry()).endpoint(|| async {}).dispatch(deps![value]).await;
}
}