axum_extra/
lib.rs

1//! Extra utilities for [`axum`].
2//!
3//! # Feature flags
4//!
5//! axum-extra uses a set of [feature flags] to reduce the amount of compiled and
6//! optional dependencies.
7//!
8//! The following optional features are available:
9//!
10//! Name | Description | Default?
11//! ---|---|---
12//! `async-read-body` | Enables the [`AsyncReadBody`](crate::body::AsyncReadBody) body | No
13//! `cookie` | Enables the [`CookieJar`](crate::extract::CookieJar) extractor | No
14//! `cookie-private` | Enables the [`PrivateCookieJar`](crate::extract::PrivateCookieJar) extractor | No
15//! `cookie-signed` | Enables the [`SignedCookieJar`](crate::extract::SignedCookieJar) extractor | No
16//! `cookie-key-expansion` | Enables the [`Key::derive_from`](crate::extract::cookie::Key::derive_from) method | No
17//! `erased-json` | Enables the [`ErasedJson`](crate::response::ErasedJson) response | No
18//! `form` | Enables the [`Form`](crate::extract::Form) extractor | No
19//! `json-deserializer` | Enables the [`JsonDeserializer`](crate::extract::JsonDeserializer) extractor | No
20//! `json-lines` | Enables the [`JsonLines`](crate::extract::JsonLines) extractor and response | No
21//! `multipart` | Enables the [`Multipart`](crate::extract::Multipart) extractor | No
22//! `protobuf` | Enables the [`Protobuf`](crate::protobuf::Protobuf) extractor and response | No
23//! `query` | Enables the [`Query`](crate::extract::Query) extractor | No
24//! `tracing` | Log rejections from built-in extractors | Yes
25//! `typed-routing` | Enables the [`TypedPath`](crate::routing::TypedPath) routing utilities | No
26//! `typed-header` | Enables the [`TypedHeader`] extractor and response | No
27//!
28//! [`axum`]: https://crates.io/crates/axum
29
30#![warn(
31    clippy::all,
32    clippy::dbg_macro,
33    clippy::todo,
34    clippy::empty_enum,
35    clippy::enum_glob_use,
36    clippy::mem_forget,
37    clippy::unused_self,
38    clippy::filter_map_next,
39    clippy::needless_continue,
40    clippy::needless_borrow,
41    clippy::match_wildcard_for_single_variants,
42    clippy::if_let_mutex,
43    clippy::await_holding_lock,
44    clippy::match_on_vec_items,
45    clippy::imprecise_flops,
46    clippy::suboptimal_flops,
47    clippy::lossy_float_literal,
48    clippy::rest_pat_in_fully_bound_structs,
49    clippy::fn_params_excessive_bools,
50    clippy::exit,
51    clippy::inefficient_to_string,
52    clippy::linkedlist,
53    clippy::macro_use_imports,
54    clippy::option_option,
55    clippy::verbose_file_reads,
56    clippy::unnested_or_patterns,
57    clippy::str_to_string,
58    rust_2018_idioms,
59    future_incompatible,
60    nonstandard_style,
61    missing_debug_implementations,
62    missing_docs
63)]
64#![deny(unreachable_pub)]
65#![allow(elided_lifetimes_in_paths, clippy::type_complexity)]
66#![forbid(unsafe_code)]
67#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
68#![cfg_attr(test, allow(clippy::float_cmp))]
69#![cfg_attr(not(test), warn(clippy::print_stdout, clippy::dbg_macro))]
70
71#[allow(unused_extern_crates)]
72extern crate self as axum_extra;
73
74pub mod body;
75pub mod either;
76pub mod extract;
77pub mod handler;
78pub mod middleware;
79pub mod response;
80pub mod routing;
81
82#[cfg(feature = "json-lines")]
83pub mod json_lines;
84
85#[cfg(feature = "typed-header")]
86pub mod typed_header;
87
88#[cfg(feature = "typed-header")]
89#[doc(no_inline)]
90pub use headers;
91
92#[cfg(feature = "typed-header")]
93#[doc(inline)]
94pub use typed_header::TypedHeader;
95
96#[cfg(feature = "protobuf")]
97pub mod protobuf;
98
99/// _not_ public API
100#[cfg(feature = "typed-routing")]
101#[doc(hidden)]
102pub mod __private {
103    use percent_encoding::{AsciiSet, CONTROLS};
104
105    pub use percent_encoding::utf8_percent_encode;
106
107    // from https://github.com/servo/rust-url/blob/master/url/src/parser.rs
108    const FRAGMENT: &AsciiSet = &CONTROLS.add(b' ').add(b'"').add(b'<').add(b'>').add(b'`');
109    const PATH: &AsciiSet = &FRAGMENT.add(b'#').add(b'?').add(b'{').add(b'}');
110    pub const PATH_SEGMENT: &AsciiSet = &PATH.add(b'/').add(b'%');
111}
112
113#[cfg(test)]
114use axum_macros::__private_axum_test as test;
115
116#[cfg(test)]
117#[allow(unused_imports)]
118pub(crate) mod test_helpers {
119    use axum::{extract::Request, response::Response, serve};
120
121    mod test_client {
122        #![allow(dead_code)]
123        include!(concat!(
124            env!("CARGO_MANIFEST_DIR"),
125            "/../axum/src/test_helpers/test_client.rs"
126        ));
127    }
128    pub(crate) use self::test_client::*;
129}