Skip to content

Commit

Permalink
Mhh
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterthanlime committed Nov 30, 2024
1 parent d5deafd commit 8520438
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
8 changes: 4 additions & 4 deletions merde_core/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ where

pub trait DynSerializerExt {
fn serialize<T: 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<S> DynSerializerExt for S
Expand All @@ -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()
}
}
Expand All @@ -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>>>;
}
Expand All @@ -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))
Expand Down
10 changes: 5 additions & 5 deletions merde_json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -53,27 +53,27 @@ where
}

/// Serialize the given data structure as a String of JSON.
pub fn to_string<T: Serialize>(value: &T) -> Result<String, MerdeError<'static>> {
pub fn to_string(value: &dyn DynSerialize) -> Result<String, MerdeError<'static>> {
// 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)?) };
Ok(res)
}

/// Serialize as JSON to a `Vec<u8>`
pub fn to_vec<T: Serialize>(value: &T) -> Result<Vec<u8>, MerdeError<'static>> {
pub fn to_vec(value: &dyn DynSerialize) -> Result<Vec<u8>, MerdeError<'static>> {
let mut v: Vec<u8> = vec![];
{
let mut s = JsonSerializer::new(&mut v);
s.serialize(value)?;
s.dyn_serialize(value)?;
}
Ok(v)
}

/// 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)?;
Expand Down

0 comments on commit 8520438

Please sign in to comment.