conduit_hyper/
lib.rs

1#![deny(clippy::all, missing_debug_implementations, rust_2018_idioms)]
2
3//! A wrapper for integrating `hyper 0.13` with a `conduit 0.8` blocking application stack.
4//!
5//! A `conduit::Handler` is allowed to block so the `Server` must be spawned on the (default)
6//! multi-threaded `Runtime` which allows (by default) 100 concurrent blocking threads.  Any excess
7//! requests will asynchronously await for an available blocking thread.
8//!
9//! # Examples
10//!
11//! Try out the example with `cargo run --example server`.
12//!
13//! Typical usage:
14//!
15//! ```no_run
16//! use conduit::Handler;
17//! use conduit_hyper::Server;
18//! use tokio::runtime::Runtime;
19//!
20//! #[tokio::main]
21//! async fn main() {
22//!     let app = build_conduit_handler();
23//!     let addr = ([127, 0, 0, 1], 12345).into();
24//!     let server = Server::serve(&addr, app);
25//!
26//!     server.await;
27//! }
28//!
29//! fn build_conduit_handler() -> impl Handler {
30//!     // ...
31//! #     Endpoint()
32//! }
33//! #
34//! # use std::{error, io};
35//! # use conduit::{box_error, Body, Response, RequestExt, HandlerResult};
36//! #
37//! # struct Endpoint();
38//! # impl Handler for Endpoint {
39//! #     fn call(&self, _: &mut dyn RequestExt) -> HandlerResult {
40//! #         Response::builder().body(Body::empty()).map_err(box_error)
41//! #     }
42//! # }
43//! ```
44
45mod adaptor;
46mod file_stream;
47mod server;
48mod service;
49#[cfg(test)]
50mod tests;
51
52pub use server::Server;
53pub use service::{BlockingHandler, Service};
54
55type HyperResponse = hyper::Response<hyper::Body>;
56type ConduitResponse = conduit::Response<conduit::Body>;