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