Skip to content

Commit

Permalink
doc: feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Totodore committed Nov 15, 2023
1 parent 5d90d32 commit 903ddc7
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 1 deletion.
6 changes: 6 additions & 0 deletions engineioxide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ keywords.workspace = true
categories.workspace = true
license.workspace = true

# docs.rs-specific configuration
[package.metadata.docs.rs]
features = ["v3", "hyper-v1"]
# Special configuration for docs.rs build
rustdoc-args = ["--cfg", "docsrs"]

[dependencies]
futures.workspace = true
http.workspace = true
Expand Down
1 change: 1 addition & 0 deletions engineioxide/src/body/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg_attr(docsrs, doc(cfg(feature = "hyper-v1")))]
#[cfg(feature = "hyper-v1")]
pub mod request;

Expand Down
3 changes: 3 additions & 0 deletions engineioxide/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ impl<H: EngineIoHandler> EngineIoLayer<H> {
}

/// Create a `hyper-v1` compatible [`Layer`]
#[cfg_attr(docsrs, doc(cfg(feature = "hyper-v1")))]
#[cfg(feature = "hyper-v1")]
#[inline(always)]
pub fn with_hyper_v1(self) -> EngineIoHyperLayer<H> {
Expand All @@ -96,10 +97,12 @@ impl<S: Clone, H: EngineIoHandler + Clone> Layer<S> for EngineIoLayer<H> {
/// Wrapper [`Layer`] for [`EngineIoLayer`] so it works with `hyper-v1`
///
/// It is only available through the feature flag `hyper-v1`
#[cfg_attr(docsrs, doc(cfg(feature = "hyper-v1")))]
#[cfg(feature = "hyper-v1")]
#[derive(Debug, Clone)]
pub struct EngineIoHyperLayer<H: EngineIoHandler>(EngineIoLayer<H>);

#[cfg_attr(docsrs, doc(cfg(feature = "hyper-v1")))]
#[cfg(feature = "hyper-v1")]
impl<S: Clone, H: EngineIoHandler + Clone> Layer<S> for EngineIoHyperLayer<H> {
type Service = crate::service::hyper_v1::EngineIoHyperService<H, S>;
Expand Down
1 change: 1 addition & 0 deletions engineioxide/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![warn(
clippy::future_not_send,
clippy::all,
Expand Down
2 changes: 2 additions & 0 deletions engineioxide/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ use crate::{
handler::EngineIoHandler,
};

#[cfg_attr(docsrs, doc(cfg(feature = "hyper-v1")))]
#[cfg(feature = "hyper-v1")]
pub mod hyper_v1;

Expand Down Expand Up @@ -104,6 +105,7 @@ impl<S: Clone, H: EngineIoHandler> EngineIoService<H, S> {
/// Create a new [`hyper_v1::EngineIoHyperService`] with this [`EngineIoService`] as the inner service.
///
/// It can be used as a compatibility layer for hyper v1.
#[cfg_attr(docsrs, doc(cfg(feature = "hyper-v1")))]
#[cfg(feature = "hyper-v1")]
#[inline(always)]
pub fn with_hyper_v1(self) -> hyper_v1::EngineIoHyperService<H, S> {
Expand Down
2 changes: 1 addition & 1 deletion engineioxide/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl From<&Error> for Option<DisconnectReason> {
}

/// A [`Socket`] represents a client connection to the server.
/// It is agnostic to the [`TransportType`](crate::service::TransportType).
/// It is agnostic to the [`TransportType`].
///
/// It handles :
/// * the packet communication between with the `Engine`
Expand Down
6 changes: 6 additions & 0 deletions socketioxide/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ hyper = { workspace = true, features = [
] }
criterion = { version = "0.5.1", features = ["html_reports"] }

# docs.rs-specific configuration
[package.metadata.docs.rs]
features = ["v4", "extensions", "hyper-v1"]
# Special configuration for docs.rs build
rustdoc-args = ["--cfg", "docsrs"]

[[bench]]
name = "packet_encode"
path = "benches/packet_encode.rs"
Expand Down
4 changes: 4 additions & 0 deletions socketioxide/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ impl<A: Adapter> SocketIoLayer<A> {
/// Convert this [`Layer`] into a [`SocketIoHyperLayer`] to use with hyper v1 and its dependent frameworks.
///
/// This is only available when the `hyper-v1` feature is enabled.
#[cfg_attr(docsrs, doc(cfg(feature = "hyper-v1")))]
#[cfg(feature = "hyper-v1")]
#[inline(always)]
pub fn with_hyper_v1(self) -> SocketIoHyperLayer<A> {
Expand All @@ -85,15 +86,18 @@ impl<S: Clone, A: Adapter> Layer<S> for SocketIoLayer<A> {
}

/// A [`Layer`] for [`SocketIoService`] that works with hyper v1 and its dependent frameworks.
#[cfg_attr(docsrs, doc(cfg(feature = "hyper-v1")))]
#[cfg(feature = "hyper-v1")]
pub struct SocketIoHyperLayer<A: Adapter>(SocketIoLayer<A>);

#[cfg_attr(docsrs, doc(cfg(feature = "hyper-v1")))]
#[cfg(feature = "hyper-v1")]
impl<A: Adapter> Clone for SocketIoHyperLayer<A> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
#[cfg_attr(docsrs, doc(cfg(feature = "hyper-v1")))]
#[cfg(feature = "hyper-v1")]
impl<S: Clone, A: Adapter> Layer<S> for SocketIoHyperLayer<A> {
type Service = crate::hyper_v1::SocketIoHyperService<S, A>;
Expand Down
3 changes: 3 additions & 0 deletions socketioxide/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![warn(
clippy::future_not_send,
clippy::all,
Expand Down Expand Up @@ -106,8 +107,10 @@
pub mod adapter;

#[cfg_attr(docsrs, doc(cfg(feature = "extensions")))]
#[cfg(feature = "extensions")]
pub mod extensions;
#[cfg_attr(docsrs, doc(cfg(feature = "hyper-v1")))]
#[cfg(feature = "hyper-v1")]
pub mod hyper_v1;

Expand Down
1 change: 1 addition & 0 deletions socketioxide/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ impl<A: Adapter, S: Clone> SocketIoService<S, A> {
///
/// This is only available when the `hyper-v1` feature is enabled.
#[inline(always)]
#[cfg_attr(docsrs, doc(cfg(feature = "hyper-v1")))]
#[cfg(feature = "hyper-v1")]
pub fn with_hyper_v1(self) -> crate::hyper_v1::SocketIoHyperService<S, A> {
crate::hyper_v1::SocketIoHyperService::new(self.engine_svc.with_hyper_v1())
Expand Down
1 change: 1 addition & 0 deletions socketioxide/src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ pub struct Socket<A: Adapter = LocalAdapter> {
/// Because it uses a [`DashMap`](dashmap::DashMap) internally, it is thread safe but be careful about deadlocks!
///
/// **Note**: This is note the same data than the `extensions` field on the [`http::Request::extensions()`](http::Request) struct.
#[cfg_attr(docsrs, doc(cfg(feature = "extensions")))]
#[cfg(feature = "extensions")]
pub extensions: Extensions,
esocket: Arc<engineioxide::Socket<SocketData>>,
Expand Down

0 comments on commit 903ddc7

Please sign in to comment.