use std::{convert::Infallible, future::Future, pin::Pin};
#[cfg(feature = "serve")]
mod serve;
#[cfg(feature = "serve")]
pub use serve::serve;
#[derive(Clone)]
pub struct ZonToHyperService<S> {
inner: S,
}
impl<S> ZonToHyperService<S> {
pub fn new(zon_service: S) -> Self {
Self { inner: zon_service }
}
}
impl<B, S> hyper::service::Service<http::Request<B>> for ZonToHyperService<S>
where
B: Send + 'static,
S: zon_core::HttpService<B> + Clone + Send + 'static,
{
type Response = http::Response<S::ResponseBody>;
type Error = Infallible;
type Future =
Pin<Box<dyn Future<Output = Result<http::Response<S::ResponseBody>, Infallible>> + Send>>;
fn call(&self, req: http::Request<B>) -> Self::Future {
let svc = self.inner.clone();
Box::pin(async move { Ok(svc.call(req).await) })
}
}