From 852043866561f93f9033596a437218776832bfa8 Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Sat, 30 Nov 2024 18:26:49 +0100 Subject: [PATCH] Mhh --- merde_core/src/serialize.rs | 8 ++++---- merde_json/src/lib.rs | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/merde_core/src/serialize.rs b/merde_core/src/serialize.rs index 8b350ee..0479960 100644 --- a/merde_core/src/serialize.rs +++ b/merde_core/src/serialize.rs @@ -39,7 +39,7 @@ where pub trait DynSerializerExt { fn serialize(&mut self, t: &T) -> Result<(), MerdeError<'static>>; - fn dyn_serialize(&mut self, t: &mut dyn DynSerialize) -> Result<(), MerdeError<'static>>; + fn dyn_serialize(&mut self, t: &dyn DynSerialize) -> Result<(), MerdeError<'static>>; } impl DynSerializerExt for S @@ -50,7 +50,7 @@ where T::serialize(t, self).run_sync_with_metastack() } - fn dyn_serialize(&mut self, t: &mut dyn DynSerialize) -> Result<(), MerdeError<'static>> { + fn dyn_serialize(&mut self, t: &dyn DynSerialize) -> Result<(), MerdeError<'static>> { DynSerialize::dyn_serialize(t, self).run_sync_with_metastack() } } @@ -66,7 +66,7 @@ pub trait Serialize { pub trait DynSerialize { /// Dynamic dispatch version of [`Serialize::serialize`]. fn dyn_serialize<'fut>( - &'fut mut self, + &'fut self, serializer: &'fut mut dyn DynSerializer, ) -> BoxFut<'fut, Result<(), MerdeError<'static>>>; } @@ -76,7 +76,7 @@ where S: Serialize, { fn dyn_serialize<'fut>( - &'fut mut self, + &'fut self, serializer: &'fut mut dyn DynSerializer, ) -> BoxFut<'fut, Result<(), MerdeError<'static>>> { Box::pin(Serialize::serialize(self, serializer)) diff --git a/merde_json/src/lib.rs b/merde_json/src/lib.rs index 9fac212..1713163 100644 --- a/merde_json/src/lib.rs +++ b/merde_json/src/lib.rs @@ -11,7 +11,7 @@ mod jiter_lite; use merde_core::{ Deserialize, DeserializeOwned, DynDeserializerExt, DynSerialize, DynSerializerExt, MerdeError, - MetastackExt, Serialize, + MetastackExt, }; /// Deserialize an instance of type `T` from a string of JSON text. @@ -53,7 +53,7 @@ where } /// Serialize the given data structure as a String of JSON. -pub fn to_string(value: &T) -> Result> { +pub fn to_string(value: &dyn DynSerialize) -> Result> { // SAFETY: This is safe because we know that the JSON serialization // produced by `to_json_bytes` will always be valid UTF-8. let res = unsafe { String::from_utf8_unchecked(to_vec(value)?) }; @@ -61,11 +61,11 @@ pub fn to_string(value: &T) -> Result> } /// Serialize as JSON to a `Vec` -pub fn to_vec(value: &T) -> Result, MerdeError<'static>> { +pub fn to_vec(value: &dyn DynSerialize) -> Result, MerdeError<'static>> { let mut v: Vec = vec![]; { let mut s = JsonSerializer::new(&mut v); - s.serialize(value)?; + s.dyn_serialize(value)?; } Ok(v) } @@ -73,7 +73,7 @@ pub fn to_vec(value: &T) -> Result, MerdeError<'static>> { /// Serialize the given data structure as JSON into the I/O stream. pub fn to_writer( writer: &mut dyn std::io::Write, - value: &mut dyn DynSerialize, + value: &dyn DynSerialize, ) -> Result<(), MerdeError<'static>> { let mut s = JsonSerializer::from_writer(writer); s.dyn_serialize(value)?;