hyper_serve/
lib.rs

1//! hyper-serve is a [hyper] server implementation designed to be used with [axum] framework.
2//!
3//! # Features
4//!
5//! - HTTP/1 and HTTP/2
6//! - HTTPS through [rustls] or [openssl].
7//! - High performance through [hyper].
8//! - Using [tower] make service API.
9//! - Very good [axum] compatibility. Likely to work with future [axum] releases.
10//!
11//! # Guide
12//!
13//! hyper-serve can [`serve`] items that implement [`MakeService`] with some additional [trait
14//! bounds](crate::service::MakeServiceRef). Make services that are [created] using [`axum`]
15//! complies with those trait bounds out of the box. Therefore it is more convenient to use this
16//! crate with [`axum`].
17//!
18//! All examples in this crate uses [`axum`]. If you want to use this crate without [`axum`] it is
19//! highly recommended to learn how [tower] works.
20//!
21//! [`Server::bind`] or [`bind`] function can be called to create a server that will bind to
22//! provided [`SocketAddr`] when [`serve`] is called.
23//!
24//! A [`Handle`] can be passed to [`Server`](Server::handle) for additional utilities like shutdown
25//! and graceful shutdown.
26//!
27//! [`bind_rustls`] can be called by providing [`RustlsConfig`] to create a HTTPS [`Server`] that
28//! will bind on provided [`SocketAddr`]. [`RustlsConfig`] can be cloned, reload methods can be
29//! used on clone to reload tls configuration.
30//!
31//! # Features
32//!
33//! * `tls-rustls` - activate [rustls] support.
34//! * `tls-openssl` - activate [openssl] support.
35//!
36//! # Example
37//!
38//! A simple hello world application can be served like:
39//!
40//! ```rust,no_run
41//! use axum::{routing::get, Router};
42//! use std::net::SocketAddr;
43//!
44//! #[tokio::main]
45//! async fn main() {
46//!     let app = Router::new().route("/", get(|| async { "Hello, world!" }));
47//!
48//!     let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
49//!     println!("listening on {}", addr);
50//!     hyper_serve::bind(addr)
51//!         .serve(app.into_make_service())
52//!         .await
53//!         .unwrap();
54//! }
55//! ```
56//!
57//! You can find more examples in [repository].
58//!
59//! [axum]: https://crates.io/crates/axum
60//! [bind]: crate::bind
61//! [bind_rustls]: crate::bind_rustls
62//! [created]: https://docs.rs/axum/0.3/axum/struct.Router.html#method.into_make_service
63//! [hyper]: https://crates.io/crates/hyper
64//! [openssl]: https://crates.io/crates/openssl
65//! [repository]: https://github.com/NOBLES5E/hyper-serve/
66//! [rustls]: https://crates.io/crates/rustls
67//! [tower]: https://crates.io/crates/tower
68//! [`axum`]: https://docs.rs/axum/0.3
69//! [`serve`]: crate::server::Server::serve
70//! [`MakeService`]: https://docs.rs/tower/0.4/tower/make/trait.MakeService.html
71//! [`RustlsConfig`]: crate::tls_rustls::RustlsConfig
72//! [`SocketAddr`]: std::net::SocketAddr
73
74#![forbid(unsafe_code)]
75#![warn(
76    clippy::await_holding_lock,
77    clippy::cargo_common_metadata,
78    clippy::dbg_macro,
79    clippy::doc_markdown,
80    clippy::empty_enum,
81    clippy::enum_glob_use,
82    clippy::inefficient_to_string,
83    clippy::mem_forget,
84    clippy::mutex_integer,
85    clippy::needless_continue,
86    clippy::todo,
87    clippy::unimplemented,
88    clippy::wildcard_imports,
89    future_incompatible,
90    missing_docs,
91    missing_debug_implementations,
92    unreachable_pub
93)]
94#![cfg_attr(docsrs, feature(doc_cfg))]
95
96mod handle;
97mod notify_once;
98mod server;
99
100pub mod accept;
101pub mod service;
102
103pub use self::{
104    // addr_incoming_config::AddrIncomingConfig,
105    handle::Handle,
106    // http_config::HttpConfig,
107    server::{bind, from_tcp, Server},
108};
109
110#[cfg(feature = "tls-rustls")]
111#[cfg_attr(docsrs, doc(cfg(feature = "tls-rustls")))]
112pub mod tls_rustls;
113
114#[doc(inline)]
115#[cfg(feature = "tls-rustls")]
116pub use self::tls_rustls::export::{bind_rustls, from_tcp_rustls};
117
118#[cfg(feature = "tls-openssl")]
119#[cfg_attr(docsrs, doc(cfg(feature = "tls-openssl")))]
120pub mod tls_openssl;
121
122#[doc(inline)]
123#[cfg(feature = "tls-openssl")]
124pub use self::tls_openssl::bind_openssl;