diff --git a/Cargo.lock b/Cargo.lock index 7a336cf76..baac07af3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -637,6 +637,7 @@ dependencies = [ "safer-ffi", "safer_ffi-proc_macros", "scopeguard", + "serde", "stabby", "tokio", "uninit", @@ -680,22 +681,22 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.156" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "314b5b092c0ade17c00142951e50ced110ec27cea304b1037c6969246c2469a4" +checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.156" +version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7e29c4601e36bcec74a223228dce795f4cd3616341a4af93520ca1a837c087d" +checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.58", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b1dbfc0e4..6194a94b3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -66,6 +66,10 @@ futures = [ "dyn-traits", ] +serde = [ + "dep:serde", +] + stabby = [ "dep:stabby", ] @@ -144,6 +148,10 @@ paste.version = "1.0.12" scopeguard.version = "1.1.0" scopeguard.default-features = false +serde.version = "1.0.204" +serde.optional = true +serde.default_features = false + stabby.version = "36.1.1-rc8" stabby.optional = true stabby.default-features = false diff --git a/src/bytes.rs b/src/bytes.rs index cf61a4cc7..95a060577 100644 --- a/src/bytes.rs +++ b/src/bytes.rs @@ -593,3 +593,17 @@ fn fuzz_stabby() { } } } + +#[cfg(feature = "serde")] +impl<'a> serde::Serialize for Bytes<'a> { + fn serialize(&self, serializer: S) -> Result { + serializer.serialize_bytes(self.as_slice()) + } +} + +#[cfg(feature = "serde")] +impl<'a, 'de: 'a> serde::Deserialize<'de> for Bytes<'a> { + fn deserialize>(deserializer: D) -> Result { + serde::Deserialize::deserialize(deserializer).map(|x: &[u8]| Bytes::from(x)) + } +}