From 89e9d1bff191d48256715a14f3c27f84ed03a169 Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Tue, 22 Feb 2022 10:12:24 +0100 Subject: [PATCH] Put the Form and Query extractors behind (default-on) Cargo features (#775) * Put the Form extractor behind a (default-activated) Cargo feature * Put the Query behind a (default-activated) Cargo feature --- axum/Cargo.toml | 6 ++++-- axum/src/extract/form.rs | 1 + axum/src/extract/mod.rs | 19 +++++++++++++++---- axum/src/extract/query.rs | 1 + 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/axum/Cargo.toml b/axum/Cargo.toml index 648b3a66..e4cc471c 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -11,13 +11,15 @@ readme = "README.md" repository = "https://github.com/tokio-rs/axum" [features] -default = ["http1", "json", "matched-path", "original-uri", "tower-log"] +default = ["form", "http1", "json", "matched-path", "original-uri", "query", "tower-log"] +form = ["serde_urlencoded"] http1 = ["hyper/http1"] http2 = ["hyper/http2"] json = ["serde_json"] matched-path = [] multipart = ["multer"] original-uri = [] +query = ["serde_urlencoded"] tower-log = ["tower/log"] ws = ["tokio-tungstenite", "sha-1", "base64"] @@ -37,7 +39,6 @@ mime = "0.3.16" percent-encoding = "2.1" pin-project-lite = "0.2.7" serde = "1.0" -serde_urlencoded = "0.7" sync_wrapper = "0.1.1" tokio = { version = "1", features = ["time"] } tower = { version = "0.4.11", default-features = false, features = ["util", "buffer", "make"] } @@ -50,6 +51,7 @@ base64 = { optional = true, version = "0.13" } headers = { optional = true, version = "0.3" } multer = { optional = true, version = "2.0.0" } serde_json = { version = "1.0", optional = true, features = ["raw_value"] } +serde_urlencoded = { version = "0.7", optional = true } sha-1 = { optional = true, version = "0.10" } tokio-tungstenite = { optional = true, version = "0.16" } diff --git a/axum/src/extract/form.rs b/axum/src/extract/form.rs index e53d722a..f47c4068 100644 --- a/axum/src/extract/form.rs +++ b/axum/src/extract/form.rs @@ -40,6 +40,7 @@ use std::ops::Deref; /// ``` /// /// Note that `Content-Type: multipart/form-data` requests are not supported. +#[cfg_attr(docsrs, doc(cfg(feature = "form")))] #[derive(Debug, Clone, Copy, Default)] pub struct Form(pub T); diff --git a/axum/src/extract/mod.rs b/axum/src/extract/mod.rs index 51440f21..128efbd3 100644 --- a/axum/src/extract/mod.rs +++ b/axum/src/extract/mod.rs @@ -13,8 +13,6 @@ pub mod ws; mod content_length_limit; mod extension; -mod form; -mod query; mod raw_query; mod request_parts; @@ -28,16 +26,22 @@ pub use self::{ content_length_limit::ContentLengthLimit, extension::Extension, extractor_middleware::extractor_middleware, - form::Form, path::Path, - query::Query, raw_query::RawQuery, request_parts::{BodyStream, RawBody}, }; + #[doc(no_inline)] #[cfg(feature = "json")] pub use crate::Json; +#[cfg(feature = "form")] +mod form; + +#[cfg(feature = "form")] +#[doc(inline)] +pub use self::form::Form; + #[cfg(feature = "matched-path")] mod matched_path; @@ -52,6 +56,13 @@ pub mod multipart; #[doc(inline)] pub use self::multipart::Multipart; +#[cfg(feature = "query")] +mod query; + +#[cfg(feature = "query")] +#[doc(inline)] +pub use self::query::Query; + #[cfg(feature = "original-uri")] #[doc(inline)] pub use self::request_parts::OriginalUri; diff --git a/axum/src/extract/query.rs b/axum/src/extract/query.rs index c60b3766..a3e7ccf0 100644 --- a/axum/src/extract/query.rs +++ b/axum/src/extract/query.rs @@ -44,6 +44,7 @@ use std::ops::Deref; /// example. /// /// [example]: https://github.com/tokio-rs/axum/blob/main/examples/query-params-with-empty-strings/src/main.rs +#[cfg_attr(docsrs, doc(cfg(feature = "query")))] #[derive(Debug, Clone, Copy, Default)] pub struct Query(pub T);