axum_server/
lib.rs

1//! axum-server 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//! axum-server can [`serve`] items that implement [`MakeService`] with some additional [trait
14//! bounds](crate::service::MakeService). 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-rustls-no-provider` - activate [rustls] support without a default provider.
35//! * `tls-openssl` - activate [openssl] support.
36//!
37//! # Example
38//!
39//! A simple hello world application can be served like:
40//!
41//! ```rust,no_run
42//! use axum::{routing::get, Router};
43//! use std::net::SocketAddr;
44//!
45//! #[tokio::main]
46//! async fn main() {
47//!     let app = Router::new().route("/", get(|| async { "Hello, world!" }));
48//!
49//!     let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
50//!     println!("listening on {}", addr);
51//!     axum_server::bind(addr)
52//!         .serve(app.into_make_service())
53//!         .await
54//!         .unwrap();
55//! }
56//! ```
57//!
58//! You can find more examples in [repository].
59//!
60//! [axum]: https://crates.io/crates/axum
61//! [bind]: crate::bind
62//! [bind_rustls]: crate::bind_rustls
63//! [created]: https://docs.rs/axum/0.3/axum/struct.Router.html#method.into_make_service
64//! [hyper]: https://crates.io/crates/hyper
65//! [openssl]: https://crates.io/crates/openssl
66//! [repository]: https://github.com/programatik29/axum-server/tree/v0.3.0/examples
67//! [rustls]: https://crates.io/crates/rustls
68//! [tower]: https://crates.io/crates/tower
69//! [`axum`]: https://docs.rs/axum/0.3
70//! [`serve`]: crate::server::Server::serve
71//! [`MakeService`]: https://docs.rs/tower/0.4/tower/make/trait.MakeService.html
72//! [`RustlsConfig`]: crate::tls_rustls::RustlsConfig
73//! [`SocketAddr`]: std::net::SocketAddr
74
75#![forbid(unsafe_code)]
76#![warn(
77    clippy::await_holding_lock,
78    clippy::cargo_common_metadata,
79    clippy::dbg_macro,
80    clippy::doc_markdown,
81    clippy::empty_enum,
82    clippy::enum_glob_use,
83    clippy::inefficient_to_string,
84    clippy::mem_forget,
85    clippy::mutex_integer,
86    clippy::needless_continue,
87    clippy::todo,
88    clippy::unimplemented,
89    clippy::wildcard_imports,
90    future_incompatible,
91    missing_docs,
92    missing_debug_implementations,
93    unreachable_pub
94)]
95#![cfg_attr(docsrs, feature(doc_cfg))]
96
97mod handle;
98mod notify_once;
99mod server;
100
101pub mod accept;
102pub mod service;
103
104pub use self::{
105    // addr_incoming_config::AddrIncomingConfig,
106    handle::Handle,
107    // http_config::HttpConfig,
108    server::{bind, from_tcp, Server},
109};
110
111#[cfg(feature = "tls-rustls-no-provider")]
112#[cfg_attr(docsrs, doc(cfg(feature = "tls-rustls")))]
113pub mod tls_rustls;
114
115#[doc(inline)]
116#[cfg(feature = "tls-rustls-no-provider")]
117pub use self::tls_rustls::export::{bind_rustls, from_tcp_rustls};
118
119#[cfg(feature = "tls-openssl")]
120#[cfg_attr(docsrs, doc(cfg(feature = "tls-openssl")))]
121pub mod tls_openssl;
122
123#[doc(inline)]
124#[cfg(feature = "tls-openssl")]
125pub use self::tls_openssl::bind_openssl;