From 6b1b40b4000124f78239a43bc5dfebf727042271 Mon Sep 17 00:00:00 2001 From: Samuel Moelius Date: Mon, 11 Nov 2024 08:23:39 -0500 Subject: [PATCH] Add `serde_ref` and `serde_ref_mut` utility modules --- examples/tests/manual_leak.rs | 5 +---- test-fuzz/src/lib.rs | 5 ++++- test-fuzz/src/utils.rs | 10 ++++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/examples/tests/manual_leak.rs b/examples/tests/manual_leak.rs index d9caa996..7fea02c5 100644 --- a/examples/tests/manual_leak.rs +++ b/examples/tests/manual_leak.rs @@ -2,10 +2,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Serialize)] pub struct WrappedKey<'key> { - #[serde( - serialize_with = "test_fuzz::serialize_ref", - deserialize_with = "test_fuzz::deserialize_ref" - )] + #[serde(with = "test_fuzz::serde_ref")] key: &'key [u8; 32], } diff --git a/test-fuzz/src/lib.rs b/test-fuzz/src/lib.rs index b80dd3bc..a0d64458 100644 --- a/test-fuzz/src/lib.rs +++ b/test-fuzz/src/lib.rs @@ -16,7 +16,10 @@ pub use cast_checks; pub use internal::serde_format; mod utils; -pub use utils::{deserialize_ref, deserialize_ref_mut, serialize_ref, serialize_ref_mut}; +pub use utils::{ + deserialize_ref, deserialize_ref_mut, serde_ref, serde_ref_mut, serialize_ref, + serialize_ref_mut, +}; mod convert; pub use convert::{FromRef, Into}; diff --git a/test-fuzz/src/utils.rs b/test-fuzz/src/utils.rs index 7716b3d2..00164044 100644 --- a/test-fuzz/src/utils.rs +++ b/test-fuzz/src/utils.rs @@ -51,6 +51,11 @@ macro_rules! leak { }; } +pub mod serde_ref { + pub use super::deserialize_ref as deserialize; + pub use super::serialize_ref as serialize; +} + /// `serialize_ref` functions similar to `leak!`, but it is meant to be used with Serde's /// [`serialize_with`](https://serde.rs/field-attrs.html#serialize_with) field attribute. #[inline] @@ -74,6 +79,11 @@ where Ok(Box::leak(Box::new(x))) } +pub mod serde_ref_mut { + pub use super::deserialize_ref_mut as deserialize; + pub use super::serialize_ref_mut as serialize; +} + /// `serialize_ref_mut` is similar to `serialize_ref`, except it operates on a mutable reference /// instead of an immutable one. pub fn serialize_ref_mut(x: &&mut T, serializer: S) -> Result