use tinyvec::{array_vec, ArrayVec};
use super::ap::state::Hydrated;
use super::ap::Hydrate;
use super::Ap;
use crate::platform::PlatformTypes;
use crate::req::Method;
pub fn is<P, T, E>(method: Method) -> impl Fn(Ap<Hydrated, P, T, E>) -> Ap<Hydrated, P, T, E>
where P: PlatformTypes,
E: core::fmt::Debug
{
is_one_of(array_vec! {_ => method})
}
pub fn is_one_of<P, T, E>(methods: ArrayVec<[Method; 5]>)
-> impl Fn(Ap<Hydrated, P, T, E>) -> Ap<Hydrated, P, T, E>
where P: PlatformTypes,
E: core::fmt::Debug
{
move |ap| match ap.try_unwrap_ok_hydrated() {
| Ok((t, h))
if methods.iter()
.any(|m| m.code() == h.req.data().as_ref().code) =>
{
Ap::ok_hydrated(t, h)
},
| Ok((_, Hydrate { req, .. })) => Ap::reject_hydrated(req).pretend(),
| Err(e) => e,
}
}
pub fn get<P, T, E>(ap: Ap<Hydrated, P, T, E>) -> Ap<Hydrated, P, T, E>
where P: PlatformTypes,
E: core::fmt::Debug
{
ap.pipe(is(Method::GET))
}
pub fn post<P, T, E>(ap: Ap<Hydrated, P, T, E>) -> Ap<Hydrated, P, T, E>
where P: PlatformTypes,
E: core::fmt::Debug
{
ap.pipe(is(Method::POST))
}
pub fn put<P, T, E>(ap: Ap<Hydrated, P, T, E>) -> Ap<Hydrated, P, T, E>
where P: PlatformTypes,
E: core::fmt::Debug
{
ap.pipe(is(Method::PUT))
}
pub fn delete<P, T, E>(ap: Ap<Hydrated, P, T, E>) -> Ap<Hydrated, P, T, E>
where P: PlatformTypes,
E: core::fmt::Debug
{
ap.pipe(is(Method::DELETE))
}