From 3c906f48ee1687342b9b46910563019cbaed12a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Frosteg=C3=A5rd?= Date: Mon, 29 Jan 2024 19:49:05 +0100 Subject: [PATCH] ws protocol: make tungstenite integration optional feature --- crates/ws_protocol/Cargo.toml | 6 +++++- crates/ws_protocol/src/incoming/mod.rs | 1 + crates/ws_protocol/src/lib.rs | 2 ++ crates/ws_protocol/src/outgoing/mod.rs | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/ws_protocol/Cargo.toml b/crates/ws_protocol/Cargo.toml index 4ae72de..3c2dd4a 100644 --- a/crates/ws_protocol/Cargo.toml +++ b/crates/ws_protocol/Cargo.toml @@ -12,6 +12,10 @@ rust-version.workspace = true readme = "./README.md" +[features] +default = ["tungstenite"] +tungstenite = ["dep:tungstenite"] + [lib] name = "aquatic_ws_protocol" @@ -26,7 +30,7 @@ hashbrown = { version = "0.14", features = ["serde"] } serde = { version = "1", features = ["derive"] } serde_json = "1" simd-json = "0.13" -tungstenite = "0.21" +tungstenite = { version = "0.21", optional = true } [dev-dependencies] criterion = "0.5" diff --git a/crates/ws_protocol/src/incoming/mod.rs b/crates/ws_protocol/src/incoming/mod.rs index 1fe48a3..517a319 100644 --- a/crates/ws_protocol/src/incoming/mod.rs +++ b/crates/ws_protocol/src/incoming/mod.rs @@ -15,6 +15,7 @@ pub enum InMessage { ScrapeRequest(ScrapeRequest), } +#[cfg(feature = "tungstenite")] impl InMessage { #[inline] pub fn to_ws_message(&self) -> ::tungstenite::Message { diff --git a/crates/ws_protocol/src/lib.rs b/crates/ws_protocol/src/lib.rs index 2652e86..1c91b00 100644 --- a/crates/ws_protocol/src/lib.rs +++ b/crates/ws_protocol/src/lib.rs @@ -227,6 +227,7 @@ mod tests { } } + #[cfg(feature = "tungstenite")] #[quickcheck] fn quickcheck_serde_identity_in_message(in_message_1: InMessage) -> bool { let ws_message = in_message_1.to_ws_message(); @@ -246,6 +247,7 @@ mod tests { success } + #[cfg(feature = "tungstenite")] #[quickcheck] fn quickcheck_serde_identity_out_message(out_message_1: OutMessage) -> bool { let ws_message = out_message_1.to_ws_message(); diff --git a/crates/ws_protocol/src/outgoing/mod.rs b/crates/ws_protocol/src/outgoing/mod.rs index c2fbaab..151fb4b 100644 --- a/crates/ws_protocol/src/outgoing/mod.rs +++ b/crates/ws_protocol/src/outgoing/mod.rs @@ -23,6 +23,7 @@ pub enum OutMessage { ErrorResponse(ErrorResponse), } +#[cfg(feature = "tungstenite")] impl OutMessage { #[inline] pub fn to_ws_message(&self) -> tungstenite::Message {