mod redirect;
use std::marker::PhantomData;
use actix_service::Service;
pub use self::redirect::Redirect;
pub trait Transform<S, Req> {
type Transform: Service<Req>;
fn new_transform(self, service: S) -> Self::Transform;
}
#[doc(hidden)]
pub struct NestTransform<T1, T2, S, Req>
where
T1: Transform<S, Req>,
T2: Transform<T1::Transform, Req>,
{
child: T1,
parent: T2,
_service: PhantomData<(S, Req)>,
}
impl<T1, T2, S, Req> NestTransform<T1, T2, S, Req>
where
T1: Transform<S, Req>,
T2: Transform<T1::Transform, Req>,
{
pub(crate) fn new(child: T1, parent: T2) -> Self {
NestTransform {
child,
parent,
_service: PhantomData,
}
}
}
impl<T1, T2, S, Req> Transform<S, Req> for NestTransform<T1, T2, S, Req>
where
T1: Transform<S, Req>,
T2: Transform<T1::Transform, Req>,
{
type Transform = T2::Transform;
fn new_transform(self, service: S) -> Self::Transform {
let service = self.child.new_transform(service);
self.parent.new_transform(service)
}
}
impl<S, Req> Transform<S, Req> for ()
where
S: Service<Req>,
{
type Transform = S;
fn new_transform(self, service: S) -> Self::Transform {
service
}
}