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` body | No
13//! `cookie` | Enables the `CookieJar` extractor | No
14//! `cookie-private` | Enables the `PrivateCookieJar` extractor | No
15//! `cookie-signed` | Enables the `SignedCookieJar` extractor | No
16//! `cookie-key-expansion` | Enables the `Key::derive_from` method | No
17//! `erased-json` | Enables the `ErasedJson` response | No
18//! `form` | Enables the `Form` extractor | No
19//! `json-deserializer` | Enables the `JsonDeserializer` extractor | No
20//! `json-lines` | Enables the `JsonLines` extractor and response | No
21//! `multipart` | Enables the `Multipart` extractor | No
22//! `protobuf` | Enables the `Protobuf` extractor and response | No
23//! `query` | Enables the `Query` extractor | No
24//! `tracing` | Log rejections from built-in extractors | Yes
25//! `typed-routing` | Enables the `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::mismatched_target_os,
44    clippy::await_holding_lock,
45    clippy::match_on_vec_items,
46    clippy::imprecise_flops,
47    clippy::suboptimal_flops,
48    clippy::lossy_float_literal,
49    clippy::rest_pat_in_fully_bound_structs,
50    clippy::fn_params_excessive_bools,
51    clippy::exit,
52    clippy::inefficient_to_string,
53    clippy::linkedlist,
54    clippy::macro_use_imports,
55    clippy::option_option,
56    clippy::verbose_file_reads,
57    clippy::unnested_or_patterns,
58    clippy::str_to_string,
59    rust_2018_idioms,
60    future_incompatible,
61    nonstandard_style,
62    missing_debug_implementations,
63    missing_docs
64)]
65#![deny(unreachable_pub)]
66#![allow(elided_lifetimes_in_paths, clippy::type_complexity)]
67#![forbid(unsafe_code)]
68#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
69#![cfg_attr(test, allow(clippy::float_cmp))]
70#![cfg_attr(not(test), warn(clippy::print_stdout, clippy::dbg_macro))]
71
72#[allow(unused_extern_crates)]
73extern crate self as axum_extra;
74
75pub mod body;
76pub mod either;
77pub mod extract;
78pub mod handler;
79pub mod middleware;
80pub mod response;
81pub mod routing;
82
83#[cfg(feature = "json-lines")]
84pub mod json_lines;
85
86#[cfg(feature = "typed-header")]
87pub mod typed_header;
88
89#[cfg(feature = "typed-header")]
90#[doc(no_inline)]
91pub use headers;
92
93#[cfg(feature = "typed-header")]
94#[doc(inline)]
95pub use typed_header::TypedHeader;
96
97#[cfg(feature = "protobuf")]
98pub mod protobuf;
99
100/// _not_ public API
101#[cfg(feature = "typed-routing")]
102#[doc(hidden)]
103pub mod __private {
104    use percent_encoding::{AsciiSet, CONTROLS};
105
106    pub use percent_encoding::utf8_percent_encode;
107
108    // from https://github.com/servo/rust-url/blob/master/url/src/parser.rs
109    const FRAGMENT: &AsciiSet = &CONTROLS.add(b' ').add(b'"').add(b'<').add(b'>').add(b'`');
110    const PATH: &AsciiSet = &FRAGMENT.add(b'#').add(b'?').add(b'{').add(b'}');
111    pub const PATH_SEGMENT: &AsciiSet = &PATH.add(b'/').add(b'%');
112}
113
114#[cfg(test)]
115use axum_macros::__private_axum_test as test;
116
117#[cfg(test)]
118#[allow(unused_imports)]
119pub(crate) mod test_helpers {
120    use axum::{extract::Request, response::Response, serve};
121
122    mod test_client {
123        #![allow(dead_code)]
124        include!(concat!(
125            env!("CARGO_MANIFEST_DIR"),
126            "/../axum/src/test_helpers/test_client.rs"
127        ));
128    }
129    pub(crate) use self::test_client::*;
130}