From 2e83dff4d152d64726055c363bcce1c018a2ce9d Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Thu, 17 Feb 2022 11:43:16 +0100 Subject: [PATCH] Fix doc(cfg)s (#765) * Use automatic doc(cfg) attributes where possible * Add missing feature documentation * Replace redundant cfg attribute with doc(cfg) * Remove non-existent feature from package.metadata.playground.features * Add missing cfg's on rejection types --- axum/Cargo.toml | 11 +++++------ axum/src/extract/mod.rs | 6 ------ axum/src/extract/multipart.rs | 1 + axum/src/extract/rejection.rs | 3 ++- axum/src/extract/typed_header.rs | 2 -- axum/src/extract/ws.rs | 1 + axum/src/lib.rs | 2 +- axum/src/response/sse.rs | 3 +-- 8 files changed, 11 insertions(+), 18 deletions(-) diff --git a/axum/Cargo.toml b/axum/Cargo.toml index a84c105d..61f108dc 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -83,10 +83,9 @@ rustdoc-args = ["--cfg", "docsrs"] [package.metadata.playground] features = [ - "http1", - "http2", - "json", - "multipart", - "tower", - "ws", + "http1", + "http2", + "json", + "multipart", + "ws", ] diff --git a/axum/src/extract/mod.rs b/axum/src/extract/mod.rs index 4fdd0ba0..2f295d3b 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,25 +42,20 @@ pub use self::{ pub use crate::Json; #[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 = "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 c3366ee0..5dcf13e8 100644 --- a/axum/src/extract/multipart.rs +++ b/axum/src/extract/multipart.rs @@ -44,6 +44,7 @@ use std::{ /// /// For security reasons its 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 13537249..05a429b9 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; @@ -243,5 +245,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 0151cfe2..ca49ef4c 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); @@ -77,7 +76,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 880ab1e2..afb4d21b 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 6f4dbc7a..1d276626 100644 --- a/axum/src/lib.rs +++ b/axum/src/lib.rs @@ -386,7 +386,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 c5b6f737..32cb1efb 100644 --- a/axum/src/response/sse.rs +++ b/axum/src/response/sse.rs @@ -210,8 +210,7 @@ impl Event { /// /// [`MessageEvent`'s data field]: https://developer.mozilla.org/en-US/docs/Web/API/MessageEvent/data #[cfg(feature = "json")] - #[cfg_attr(docsrs, doc(cfg(feature = "json")))] - pub fn json_data(mut self, data: T) -> Result + pub fn json_data(mut self, data: T) -> serde_json::Result where T: serde::Serialize, {