diff --git a/axum/Cargo.toml b/axum/Cargo.toml index 6b97386c..648b3a66 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -90,6 +90,5 @@ features = [ "http2", "json", "multipart", - "tower", "ws", ] diff --git a/axum/src/extract/matched_path.rs b/axum/src/extract/matched_path.rs index d98e4f43..8965bd30 100644 --- a/axum/src/extract/matched_path.rs +++ b/axum/src/extract/matched_path.rs @@ -52,6 +52,7 @@ use std::sync::Arc; /// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); /// # }; /// ``` +#[cfg_attr(docsrs, doc(cfg(feature = "matched-path")))] #[derive(Clone, Debug)] pub struct MatchedPath(pub(crate) Arc); diff --git a/axum/src/extract/mod.rs b/axum/src/extract/mod.rs index 8e4c8e99..51440f21 100644 --- a/axum/src/extract/mod.rs +++ b/axum/src/extract/mod.rs @@ -9,7 +9,6 @@ pub mod path; pub mod rejection; #[cfg(feature = "ws")] -#[cfg_attr(docsrs, doc(cfg(feature = "ws")))] pub mod ws; mod content_length_limit; @@ -43,35 +42,28 @@ pub use crate::Json; mod matched_path; #[cfg(feature = "matched-path")] -#[cfg_attr(docsrs, doc(cfg(feature = "matched-path")))] #[doc(inline)] pub use self::matched_path::MatchedPath; #[cfg(feature = "multipart")] -#[cfg_attr(docsrs, doc(cfg(feature = "multipart")))] pub mod multipart; #[cfg(feature = "multipart")] -#[cfg_attr(docsrs, doc(cfg(feature = "multipart")))] #[doc(inline)] pub use self::multipart::Multipart; #[cfg(feature = "original-uri")] -#[cfg_attr(docsrs, doc(cfg(feature = "original-uri")))] #[doc(inline)] pub use self::request_parts::OriginalUri; #[cfg(feature = "ws")] -#[cfg_attr(docsrs, doc(cfg(feature = "ws")))] #[doc(inline)] pub use self::ws::WebSocketUpgrade; #[cfg(feature = "headers")] -#[cfg_attr(docsrs, doc(cfg(feature = "headers")))] mod typed_header; #[cfg(feature = "headers")] -#[cfg_attr(docsrs, doc(cfg(feature = "headers")))] #[doc(inline)] pub use self::typed_header::TypedHeader; diff --git a/axum/src/extract/multipart.rs b/axum/src/extract/multipart.rs index 26138149..bfe4b7a1 100644 --- a/axum/src/extract/multipart.rs +++ b/axum/src/extract/multipart.rs @@ -43,6 +43,7 @@ use std::{ /// /// For security reasons it's recommended to combine this with /// [`ContentLengthLimit`](super::ContentLengthLimit) to limit the size of the request payload. +#[cfg_attr(docsrs, doc(cfg(feature = "multipart")))] #[derive(Debug)] pub struct Multipart { inner: multer::Multipart<'static>, diff --git a/axum/src/extract/rejection.rs b/axum/src/extract/rejection.rs index 7f5efbf0..02e3b31a 100644 --- a/axum/src/extract/rejection.rs +++ b/axum/src/extract/rejection.rs @@ -18,9 +18,11 @@ define_rejection! { pub struct InvalidJsonBody(Error); } +#[cfg(feature = "json")] define_rejection! { #[status = UNSUPPORTED_MEDIA_TYPE] #[body = "Expected request with `Content-Type: application/json`"] + #[cfg_attr(docsrs, doc(cfg(feature = "json")))] /// Rejection type for [`Json`](super::Json) used if the `Content-Type` /// header is missing. pub struct MissingJsonContentType; @@ -163,17 +165,21 @@ composite_rejection! { } } +#[cfg(feature = "matched-path")] define_rejection! { #[status = INTERNAL_SERVER_ERROR] #[body = "No matched path found"] /// Rejection if no matched path could be found. /// /// See [`MatchedPath`](super::MatchedPath) for more details. + #[cfg_attr(docsrs, doc(cfg(feature = "matched-path")))] pub struct MatchedPathMissing; } +#[cfg(feature = "matched-path")] composite_rejection! { /// Rejection used for [`MatchedPath`](super::MatchedPath). + #[cfg_attr(docsrs, doc(cfg(feature = "matched-path")))] pub enum MatchedPathRejection { MatchedPathMissing, } @@ -234,5 +240,4 @@ where } #[cfg(feature = "headers")] -#[cfg_attr(docsrs, doc(cfg(feature = "headers")))] pub use super::typed_header::{TypedHeaderRejection, TypedHeaderRejectionReason}; diff --git a/axum/src/extract/typed_header.rs b/axum/src/extract/typed_header.rs index 7bb52c53..85c9d557 100644 --- a/axum/src/extract/typed_header.rs +++ b/axum/src/extract/typed_header.rs @@ -30,7 +30,6 @@ use std::ops::Deref; /// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); /// # }; /// ``` -#[cfg(feature = "headers")] #[cfg_attr(docsrs, doc(cfg(feature = "headers")))] #[derive(Debug, Clone, Copy)] pub struct TypedHeader(pub T); @@ -68,7 +67,6 @@ impl Deref for TypedHeader { /// Rejection used for [`TypedHeader`](super::TypedHeader). #[cfg(feature = "headers")] -#[cfg_attr(docsrs, doc(cfg(feature = "headers")))] #[derive(Debug)] pub struct TypedHeaderRejection { name: &'static http::header::HeaderName, diff --git a/axum/src/extract/ws.rs b/axum/src/extract/ws.rs index 8079be1a..44dc8ae9 100644 --- a/axum/src/extract/ws.rs +++ b/axum/src/extract/ws.rs @@ -103,6 +103,7 @@ use tokio_tungstenite::{ /// /// See the [module docs](self) for an example. #[derive(Debug)] +#[cfg_attr(docsrs, doc(cfg(feature = "ws")))] pub struct WebSocketUpgrade { config: WebSocketConfig, /// The chosen protocol sent in the `Sec-WebSocket-Protocol` header of the response. diff --git a/axum/src/lib.rs b/axum/src/lib.rs index f421c573..1247b900 100644 --- a/axum/src/lib.rs +++ b/axum/src/lib.rs @@ -389,7 +389,7 @@ #![deny(unreachable_pub, private_in_public)] #![allow(elided_lifetimes_in_paths, clippy::type_complexity)] #![forbid(unsafe_code)] -#![cfg_attr(docsrs, feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))] #![cfg_attr(test, allow(clippy::float_cmp))] #[macro_use] diff --git a/axum/src/response/sse.rs b/axum/src/response/sse.rs index f1de75b0..692d30f1 100644 --- a/axum/src/response/sse.rs +++ b/axum/src/response/sse.rs @@ -204,7 +204,6 @@ impl Event { /// /// Panics if `data` or `json_data` have already been called. #[cfg(feature = "json")] - #[cfg_attr(docsrs, doc(cfg(feature = "json")))] pub fn json_data(mut self, data: T) -> serde_json::Result where T: serde::Serialize,