From 5729bf458154b97e69d553cbe2e04779c5b934fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtte?= Date: Sat, 21 Feb 2026 18:45:32 +0100 Subject: [PATCH 1/4] Make ChannelTask public, but hidden in docu --- src/channel_task.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/channel_task.rs b/src/channel_task.rs index 1205f5b..23f26f2 100644 --- a/src/channel_task.rs +++ b/src/channel_task.rs @@ -34,7 +34,8 @@ pub struct ChannelTask { impl ChannelTask { /// Create a new `ChannelTask` from a channel and a result receiver. - pub(crate) fn new(channel: Channel, result_rx: oneshot::Receiver>) -> Self { + #[doc(hidden)] + pub fn new(channel: Channel, result_rx: oneshot::Receiver>) -> Self { Self { channel, result_rx, From bf0494146b2869de79d4eec35f2a34d3b65b21fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtte?= Date: Sun, 1 Mar 2026 20:04:40 +0100 Subject: [PATCH 2/4] Added pot as optional dependency --- Cargo.toml | 7 +++++-- src/convert.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6c998e6..40c5d56 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,6 @@ keywords.workspace = true [dependencies] futures = "0.3" js-sys = { version = "0.3" } -postcard = { version = "1.1", features = ["alloc"] } send_wrapper = "0.6" serde = { version = "1.0", features = ["derive"] } serde_bytes = "0.11" @@ -40,6 +39,8 @@ tokio = { version = "1.4", features = ["sync"] } wasm-bindgen = "0.2" wasm-bindgen-futures = "0.4" log = "0.4" +postcard = { version = "1.1", features = ["alloc"], optional = true } +pot = { version = "3.0.1", optional = true } [dependencies.web-sys] features = [ @@ -63,5 +64,7 @@ version = "0.3" wasmworker-proc-macro = { workspace = true } [features] -default = ["serde"] +default = ["serde", "codec-postcard"] serde = [] +codec-postcard = ["dep:postcard"] +codec-pot = ["dep:pot"] diff --git a/src/convert.rs b/src/convert.rs index 0b1be58..ffd3559 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -3,6 +3,7 @@ use serde::{Deserialize, Serialize}; /// This wrapper function encapsulates our internal serialization format. /// It is used internally to prepare values before sending them to a worker /// or back to the main thread via `postMessage`. +#[cfg(feature = "codec-postcard")] pub fn to_bytes(value: &T) -> Box<[u8]> { postcard::to_allocvec(value) .expect("WebWorker serialization failed") @@ -12,6 +13,31 @@ pub fn to_bytes(value: &T) -> Box<[u8]> { /// This wrapper function encapsulates our internal serialization format. /// It is used internally to prepare values after receiving them from a worker /// or the main thread via `postMessage`. +#[cfg(feature = "codec-postcard")] pub fn from_bytes<'de, T: Deserialize<'de>>(bytes: &'de [u8]) -> T { postcard::from_bytes(bytes).expect("WebWorker deserialization failed") } + +#[cfg(feature = "codec-pot")] +pub const POT_CONFIG: pot::Config = pot::Config::new().compatibility(pot::Compatibility::V4); + +/// This wrapper function encapsulates our internal serialization format. +/// It is used internally to prepare values before sending them to a worker +/// or back to the main thread via `postMessage`. +#[cfg(feature = "codec-pot")] +pub fn to_bytes(value: &T) -> Box<[u8]> { + POT_CONFIG + .serialize(self) + .expect("WebWorker serialization failed") + .into() +} + +/// This wrapper function encapsulates our internal serialization format. +/// It is used internally to prepare values after receiving them from a worker +/// or the main thread via `postMessage`. +#[cfg(feature = "codec-pot")] +pub fn from_bytes<'de, T: Deserialize<'de>>(bytes: &'de [u8]) -> T { + POT_CONFIG + .deserialize(bytes) + expect("WebWorker deserialization failed") +} From d6814c1ed89d8429a76892f9ec2dfcfa38d8f81e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtte?= Date: Sun, 1 Mar 2026 20:08:58 +0100 Subject: [PATCH 3/4] Fixed build errors --- Cargo.lock | 29 +++++++++++++++++++++++++++++ src/convert.rs | 4 ++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 17cfeff..07ee638 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -44,6 +44,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" +[[package]] +name = "crunchy" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" + [[package]] name = "embedded-io" version = "0.4.0" @@ -158,6 +164,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "half" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ea2d84b969582b4b1864a92dc5d27cd2b77b622a8d79306834f1be5ba20d84b" +dependencies = [ + "cfg-if", + "crunchy", + "zerocopy", +] + [[package]] name = "hash32" version = "0.2.1" @@ -249,6 +266,17 @@ dependencies = [ "serde", ] +[[package]] +name = "pot" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf741fa415952eb20f27fbc210dc85f31cc7cdc80aa3ce81d5e27d28a6f45dc2" +dependencies = [ + "byteorder", + "half", + "serde", +] + [[package]] name = "ppv-lite86" version = "0.2.21" @@ -530,6 +558,7 @@ dependencies = [ "js-sys", "log", "postcard", + "pot", "send_wrapper", "serde", "serde-wasm-bindgen", diff --git a/src/convert.rs b/src/convert.rs index ffd3559..7bac66b 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -27,7 +27,7 @@ pub const POT_CONFIG: pot::Config = pot::Config::new().compatibility(pot::Compat #[cfg(feature = "codec-pot")] pub fn to_bytes(value: &T) -> Box<[u8]> { POT_CONFIG - .serialize(self) + .serialize(value) .expect("WebWorker serialization failed") .into() } @@ -39,5 +39,5 @@ pub fn to_bytes(value: &T) -> Box<[u8]> { pub fn from_bytes<'de, T: Deserialize<'de>>(bytes: &'de [u8]) -> T { POT_CONFIG .deserialize(bytes) - expect("WebWorker deserialization failed") + .expect("WebWorker deserialization failed") } From 2e1022fb03f4faad64ef3647d3c06a3eb21bfd27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtte?= Date: Sun, 1 Mar 2026 20:16:04 +0100 Subject: [PATCH 4/4] Fixed clippy all features build --- .github/workflows/test.yml | 3 ++- src/convert.rs | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7222ddb..9a9d5c4 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,8 @@ jobs: with: components: clippy - uses: Swatinem/rust-cache@v2 - - run: cargo clippy --all-features -- -D warnings + - run: cargo clippy --no-default-features --features "serde,codec-postcard" -- -D warnings + - run: cargo clippy --no-default-features --features "serde,codec-pot" -- -D warnings doc-test: runs-on: ubuntu-latest diff --git a/src/convert.rs b/src/convert.rs index 7bac66b..ab829f9 100644 --- a/src/convert.rs +++ b/src/convert.rs @@ -41,3 +41,10 @@ pub fn from_bytes<'de, T: Deserialize<'de>>(bytes: &'de [u8]) -> T { .deserialize(bytes) .expect("WebWorker deserialization failed") } + +// Enforce exactly one: +#[cfg(all(feature = "codec-postcard", feature = "codec-pot"))] +compile_error!("Enable only one of: codec-postcard, codec-pot"); + +#[cfg(not(any(feature = "codec-postcard", feature = "codec-pot")))] +compile_error!("Enable one of: codec-postcard, codec-pot");