zon_hyper 0.0.3

part of a new WIP, very incomplete async http service stack
Documentation
use std::{convert::Infallible, future::Future, pin::Pin};

#[cfg(feature = "serve")]
mod serve;

#[cfg(feature = "serve")]
pub use serve::serve;

/// Wraps a zon [`HttpService`][zon_core::HttpService] and implements
/// [`hyper::service::Service`].
///
/// The zon service needs to implement [`Clone`]. If you have a service that
/// doesn't, you can trivially make one that does from it by wrapping it in an
/// [`Arc`][std::sync::Arc] first.
#[derive(Clone)]
pub struct ZonToHyperService<S> {
    inner: S,
}

impl<S> ZonToHyperService<S> {
    /// Create a new `ZonToHyperService` from a tower service.
    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) })
    }
}