From 0feb5555c92ac88ea8598ac0de4c3efe77f2bfbe Mon Sep 17 00:00:00 2001 From: koe Date: Sat, 6 Jan 2024 21:48:13 -0600 Subject: [PATCH] improve feature documentation --- src/client.rs | 1 + src/client_connectors/mod.rs | 2 ++ src/lib.rs | 11 ++++++++++- src/server_runners/axum_tungstenite.rs | 2 +- src/server_runners/mod.rs | 3 +++ src/server_runners/tungstenite.rs | 4 ++++ 6 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/client.rs b/src/client.rs index ed768dd..cdec61d 100644 --- a/src/client.rs +++ b/src/client.rs @@ -414,6 +414,7 @@ impl Client { /// - Requires feature `native_client`. /// - May only be invoked from within a tokio runtime. #[cfg(feature = "native_client")] +#[cfg_attr(docsrs, doc(cfg(feature = "native_client")))] pub async fn connect( client_fn: impl FnOnce(Client) -> E, config: ClientConfig, diff --git a/src/client_connectors/mod.rs b/src/client_connectors/mod.rs index 5603a46..628d34b 100644 --- a/src/client_connectors/mod.rs +++ b/src/client_connectors/mod.rs @@ -1,5 +1,6 @@ cfg_if::cfg_if! { if #[cfg(all(feature = "native_client", not(target_family = "wasm")))] { + #[cfg_attr(docsrs, doc(cfg(all(feature = "native_client", not(target_family = "wasm")))))] mod client_connector_tokio; pub use client_connector_tokio::*; } @@ -7,6 +8,7 @@ cfg_if::cfg_if! { cfg_if::cfg_if! { if #[cfg(all(feature = "wasm_client", target_family = "wasm"))] { + #[cfg_attr(docsrs, doc(cfg(all(feature = "wasm_client", target_family = "wasm"))))] mod client_connector_wasm; pub use client_connector_wasm::*; } diff --git a/src/lib.rs b/src/lib.rs index b3715c7..1f96c91 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,6 +5,8 @@ //! //! Refer to [`client`] or [`server`] module for detailed implementation guides. +#![cfg_attr(docsrs, feature(doc_cfg))] + mod socket; mod tungstenite_common; @@ -21,7 +23,9 @@ pub use socket::Stream; cfg_if::cfg_if! { if #[cfg(feature = "client")] { + #[cfg_attr(docsrs, doc(cfg(feature = "client")))] pub mod client; + #[cfg_attr(docsrs, doc(cfg(feature = "client")))] mod client_connectors; pub use client_connectors::*; @@ -38,10 +42,15 @@ cfg_if::cfg_if! { cfg_if::cfg_if! { if #[cfg(feature = "server")] { + #[cfg_attr(docsrs, doc(cfg(feature = "server")))] pub mod server; + #[cfg_attr(docsrs, doc(cfg(feature = "server")))] pub mod session; - mod server_runners; + #[cfg(any(feature = "axum", feature = "tungstenite"))] + #[cfg_attr(docsrs, doc(cfg(feature = "server")))] + pub mod server_runners; + #[cfg(any(feature = "axum", feature = "tungstenite"))] pub use server_runners::*; pub use server::Server; diff --git a/src/server_runners/axum_tungstenite.rs b/src/server_runners/axum_tungstenite.rs index 62b65ec..7593021 100644 --- a/src/server_runners/axum_tungstenite.rs +++ b/src/server_runners/axum_tungstenite.rs @@ -3,7 +3,7 @@ //! This module implements an axum-based websockets layer on top of tungstenite, as an alternative to `axum::extract::ws` //! which does not expose tungstenite types. -#![deny(unreachable_pub, private_in_public)] +#![deny(unreachable_pub)] #![allow(clippy::type_complexity)] #![forbid(unsafe_code)] #![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg))] diff --git a/src/server_runners/mod.rs b/src/server_runners/mod.rs index 6e43800..c4e33f0 100644 --- a/src/server_runners/mod.rs +++ b/src/server_runners/mod.rs @@ -1,9 +1,12 @@ cfg_if::cfg_if! { if #[cfg(feature = "axum")] { + #[cfg_attr(docsrs, doc(cfg(feature = "axum")))] pub mod axum; + #[cfg_attr(docsrs, doc(cfg(feature = "axum")))] pub mod axum_tungstenite; } } #[cfg(feature = "tungstenite")] +#[cfg_attr(docsrs, doc(cfg(feature = "tungstenite")))] pub mod tungstenite; diff --git a/src/server_runners/tungstenite.rs b/src/server_runners/tungstenite.rs index 3fcbad0..aa5f889 100644 --- a/src/server_runners/tungstenite.rs +++ b/src/server_runners/tungstenite.rs @@ -49,9 +49,13 @@ use tokio::net::ToSocketAddrs; pub enum Acceptor { Plain, + #[cfg(feature = "native-tls")] + #[cfg_attr(docsrs, doc(cfg(feature = "native-tls")))] NativeTls(tokio_native_tls::TlsAcceptor), + #[cfg(feature = "rustls")] + #[cfg_attr(docsrs, doc(cfg(feature = "rustls")))] Rustls(tokio_rustls::TlsAcceptor), }