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//! `attachment` | Enables the [`Attachment`](crate::response::Attachment) response | No
14//! `cached` | Enables the [`Cached`](crate::extract::Cached) extractor | No
15//! `cookie` | Enables the [`CookieJar`](crate::extract::CookieJar) extractor | No
16//! `cookie-private` | Enables the [`PrivateCookieJar`](crate::extract::PrivateCookieJar) extractor | No
17//! `cookie-signed` | Enables the [`SignedCookieJar`](crate::extract::SignedCookieJar) extractor | No
18//! `cookie-key-expansion` | Enables the [`Key::derive_from`](crate::extract::cookie::Key::derive_from) method | No
19//! `erased-json` | Enables the [`ErasedJson`](crate::response::ErasedJson) response | No
20//! `error-response` | Enables the [`InternalServerError`](crate::response::InternalServerError) response | No
21//! `form` | Enables the [`Form`](crate::extract::Form) extractor | No
22//! `handler` | Enables the [handler] utilities | No
23//! `json-deserializer` | Enables the [`JsonDeserializer`](crate::extract::JsonDeserializer) extractor | No
24//! `json-lines` | Enables the [`JsonLines`](crate::extract::JsonLines) extractor and response | No
25//! `middleware` | Enables the [middleware] utilities | No
26//! `multipart` | Enables the [`Multipart`](crate::extract::Multipart) extractor | No
27//! `optional-path` | Enables the [`OptionalPath`](crate::extract::OptionalPath) extractor | No
28//! `protobuf` | Enables the [`Protobuf`](crate::protobuf::Protobuf) extractor and response | No
29//! `query` | Enables the [`Query`](crate::extract::Query) extractor | No
30//! `routing` | Enables the [routing] utilities | No
31//! `tracing` | Log rejections from built-in extractors | Yes
32//! `typed-routing` | Enables the [`TypedPath`](crate::routing::TypedPath) routing utilities | No
33//! `typed-header` | Enables the [`TypedHeader`] extractor and response | No
34//! `file-stream` | Enables the [`FileStream`](crate::response::FileStream) response | No
35//! `with-rejection` | Enables the [`WithRejection`](crate::extract::WithRejection) extractor | No
36//!
37//! [`axum`]: https://crates.io/crates/axum
38
39#![cfg_attr(docsrs, feature(doc_cfg))]
40#![cfg_attr(test, allow(clippy::float_cmp))]
41#![cfg_attr(not(test), warn(clippy::print_stdout, clippy::dbg_macro))]
42
43#[allow(unused_extern_crates)]
44extern crate self as axum_extra;
45
46pub mod body;
47pub mod either;
48pub mod extract;
49pub mod response;
50
51#[cfg(feature = "routing")]
52pub mod routing;
53
54#[cfg(feature = "middleware")]
55pub mod middleware;
56
57#[cfg(feature = "handler")]
58pub mod handler;
59
60#[cfg(feature = "json-lines")]
61pub mod json_lines;
62
63#[cfg(feature = "typed-header")]
64pub mod typed_header;
65
66#[cfg(feature = "typed-header")]
67#[doc(no_inline)]
68pub use headers;
69
70#[cfg(feature = "typed-header")]
71#[doc(inline)]
72pub use typed_header::TypedHeader;
73
74#[cfg(feature = "protobuf")]
75pub mod protobuf;
76
77/// _not_ public API
78#[cfg(feature = "typed-routing")]
79#[doc(hidden)]
80pub mod __private {
81    use percent_encoding::{AsciiSet, CONTROLS};
82
83    pub use percent_encoding::utf8_percent_encode;
84
85    // from https://github.com/servo/rust-url/blob/master/url/src/parser.rs
86    const FRAGMENT: &AsciiSet = &CONTROLS.add(b' ').add(b'"').add(b'<').add(b'>').add(b'`');
87    const PATH: &AsciiSet = &FRAGMENT.add(b'#').add(b'?').add(b'{').add(b'}');
88    pub const PATH_SEGMENT: &AsciiSet = &PATH.add(b'/').add(b'%');
89}
90
91#[cfg(test)]
92use axum_macros::__private_axum_test as test;
93
94#[cfg(test)]
95pub(crate) use axum::test_helpers;