pub mod handler;
mod middleware;
pub use middleware::{Fangs, util::FangAction};
mod builtin;
pub use builtin::*;
pub mod bound;
pub(crate) use bound::*;
use crate::{Request, Response};
use std::{future::Future, ops::Deref, pin::Pin};
#[cfg(feature = "openapi")]
use crate::openapi;
pub trait Fang<Inner: FangProc>: SendSyncOnThreaded + 'static {
type Proc: FangProc;
fn chain(&self, inner: Inner) -> Self::Proc;
#[cfg(feature = "openapi")]
fn openapi_map_operation(&self, operation: openapi::Operation) -> openapi::Operation {
operation
}
}
pub trait FangProc: SendSyncOnThreaded + 'static {
#[cfg(not(feature = "__rt_threaded__"))]
fn bite<'b>(&'b self, req: &'b mut Request) -> impl Future<Output = Response>;
#[cfg(feature = "__rt_threaded__")]
fn bite<'b>(&'b self, req: &'b mut Request) -> impl Future<Output = Response> + Send;
#[inline(always)]
fn bite_boxed<'b>(
&'b self,
req: &'b mut Request,
) -> Pin<Box<dyn SendOnThreadedFuture<Response> + 'b>> {
Box::pin(self.bite(req))
}
}
pub(crate) trait FangProcCaller {
fn call_bite<'b>(
&'b self,
req: &'b mut Request,
) -> Pin<Box<dyn SendOnThreadedFuture<Response> + 'b>>;
}
impl<Proc: FangProc> FangProcCaller for Proc {
#[inline(always)]
fn call_bite<'b>(
&'b self,
req: &'b mut Request,
) -> Pin<Box<dyn SendOnThreadedFuture<Response> + 'b>> {
self.bite_boxed(req)
}
}
pub(crate) struct BoxedFPC(Box<dyn FPCBound + 'static>);
const _: () = {
impl BoxedFPC {
pub(crate) fn from_proc(proc: impl FPCBound + 'static) -> Self {
Self(Box::new(proc))
}
}
impl Deref for BoxedFPC {
type Target = dyn FPCBound + 'static;
#[inline(always)]
fn deref(&self) -> &Self::Target {
&*self.0
}
}
impl std::fmt::Debug for BoxedFPC {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str("{Fang proc}")
}
}
impl FangProc for BoxedFPC {
#[allow(refining_impl_trait)]
#[inline(always)]
fn bite<'b>(&'b self, req: &'b mut Request) -> impl SendOnThreadedFuture<Response> {
self.0.call_bite(req)
}
#[inline]
fn bite_boxed<'b>(
&'b self,
req: &'b mut Request,
) -> Pin<Box<dyn SendOnThreadedFuture<Response> + 'b>> {
self.0.call_bite(req)
}
}
};