skyzen_core/
server.rs

1use core::{error::Error, future::Future};
2use executor_core::Executor;
3use http_kit::{
4    utils::{AsyncRead, AsyncWrite, Stream},
5    Endpoint,
6};
7
8/// Abstraction over HTTP server backends.
9pub trait Server {
10    /// Serve an [`Endpoint`] over a stream of connections.
11    ///
12    /// The provided `executor` runs background tasks created by the server while the `error_handler`
13    /// is used to report connection-accept errors surfaced by `connections`.
14    fn serve<C, E>(
15        self,
16        executor: impl Executor + 'static,
17        error_handler: impl Fn(E) + Send + Sync + 'static,
18        connections: impl Stream<Item = Result<C, E>> + Unpin + Send + 'static,
19        endpoint: impl Endpoint + Sync + Clone + 'static,
20    ) -> impl Future<Output = ()>
21    where
22        C: Unpin + Send + AsyncRead + AsyncWrite + 'static,
23        E: Error;
24}