pub(crate) mod anypoint;
pub(crate) mod ldap;
pub(crate) mod os;
pub mod trace;
mod utils;
use crate::{UnitGrpcRequest, UnitGrpcResponse, UnitHttpRequest, UnitHttpResponse};
use std::rc::Rc;
pub trait Backend {
fn call(&self, req: UnitHttpRequest) -> UnitHttpResponse;
}
impl<F> Backend for F
where
F: Fn(UnitHttpRequest) -> UnitHttpResponse,
{
fn call(&self, req: UnitHttpRequest) -> UnitHttpResponse {
self(req)
}
}
impl<B: Backend> Backend for Rc<B> {
fn call(&self, req: UnitHttpRequest) -> UnitHttpResponse {
self.as_ref().call(req)
}
}
impl Backend for UnitHttpResponse {
fn call(&self, _: UnitHttpRequest) -> UnitHttpResponse {
self.clone()
}
}
pub trait GrpcBackend {
fn call(&self, req: UnitGrpcRequest) -> UnitGrpcResponse;
}
impl<F> GrpcBackend for F
where
F: Fn(UnitGrpcRequest) -> UnitGrpcResponse,
{
fn call(&self, req: UnitGrpcRequest) -> UnitGrpcResponse {
self(req)
}
}
impl<B: GrpcBackend> GrpcBackend for Rc<B> {
fn call(&self, req: UnitGrpcRequest) -> UnitGrpcResponse {
self.as_ref().call(req)
}
}
impl GrpcBackend for UnitGrpcResponse {
fn call(&self, _: UnitGrpcRequest) -> UnitGrpcResponse {
self.clone()
}
}