Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 7b0621a

Browse files
fix: make more calls to trait functions, or trait methods, fully qualified to avoid clenches with serde
1 parent 0e28060 commit 7b0621a

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

merde/src/lib.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ macro_rules! impl_deserialize {
2323
async fn deserialize(__de: &mut dyn $crate::DynDeserializer<'s>) -> Result<Self, $crate::MerdeError<'s>> {
2424
use $crate::DynDeserializerExt;
2525

26-
Ok(Self(__de.t().await?))
26+
Ok(Self($crate::Deserialize::deserialize(__de).await?))
2727
}
2828
}
2929
};
@@ -34,9 +34,7 @@ macro_rules! impl_deserialize {
3434
impl<$s> $crate::Deserialize<$s> for $struct_name<$s> {
3535
#[inline(always)]
3636
async fn deserialize(__de: &mut dyn $crate::DynDeserializer<'s>) -> Result<Self, $crate::MerdeError<'s>> {
37-
use $crate::DynDeserializerExt;
38-
39-
Ok(Self(__de.t().await?))
37+
Ok(Self($crate::DynDeserializerExt::t(__de).await?))
4038
}
4139
}
4240
};
@@ -69,7 +67,7 @@ macro_rules! impl_deserialize {
6967
let __key = __opinions.map_key_name(__key);
7068
match __key.as_ref() {
7169
$(stringify!($field) => {
72-
$field = Some(__de.t().await?);
70+
$field = Some($crate::DynDeserializerExt::t(__de).await?);
7371
})*
7472
_ => {
7573
if __opinions.deny_unknown_fields() {
@@ -114,7 +112,7 @@ macro_rules! impl_deserialize {
114112
#[inline(always)]
115113
async fn deserialize(__de: &mut dyn $crate::DynDeserializer<$s>) -> Result<Self, $crate::MerdeError<$s>> {
116114
#![allow(unreachable_code)]
117-
use $crate::{DeserOpinions, DynDeserializerExt};
115+
use $crate::DeserOpinions;
118116

119117
let __opinions = $opinions;
120118
__de.next().await?.into_map_start()?;
@@ -130,7 +128,7 @@ macro_rules! impl_deserialize {
130128
let __key = __opinions.map_key_name(__key);
131129
match __key.as_ref() {
132130
$(stringify!($field) => {
133-
$field = Some(__de.t().await?);
131+
$field = Some($crate::DynDeserializerExt::t(__de).await?);
134132
})*
135133
_ => {
136134
if __opinions.deny_unknown_fields() {
@@ -177,7 +175,7 @@ macro_rules! impl_deserialize {
177175
let key = __de.next().await?.into_str()?;
178176
match key.as_ref() {
179177
$($variant_str => {
180-
let value = __de.t().await?;
178+
let value = $crate::Deserialize::deserialize(__de).await?;
181179
__de.next().await?.into_map_end()?;
182180
Ok($enum_name::$variant(value))
183181
},)*
@@ -202,7 +200,7 @@ macro_rules! impl_deserialize {
202200
let key = __de.next().await?.into_str()?;
203201
match key.as_ref() {
204202
$($variant_str => {
205-
let value = __de.t().await?;
203+
let value = $crate::DynDeserializerExt::t(__de).await?;
206204
__de.next().await?.into_map_end()?;
207205
Ok($enum_name::$variant(value))
208206
},)*
@@ -265,7 +263,7 @@ macro_rules! impl_into_static {
265263

266264
#[inline(always)]
267265
fn into_static(self) -> Self::Output {
268-
$struct_name(self.0.into_static())
266+
$struct_name($crate::IntoStatic::into_static(self.0))
269267
}
270268
}
271269
};
@@ -294,7 +292,7 @@ macro_rules! impl_into_static {
294292
use $crate::IntoStatic;
295293

296294
$struct_name {
297-
$($field: self.$field.into_static(),)+
295+
$($field: $crate::IntoStatic::into_static(self.$field),)+
298296
}
299297
}
300298
}
@@ -449,7 +447,7 @@ macro_rules! impl_serialize {
449447
serializer: &'fut mut dyn $crate::DynSerializer,
450448
) -> impl ::std::future::Future<Output = Result<(), $crate::MerdeError<'static>>> + 'fut {
451449
async move {
452-
self.0.serialize(serializer).await
450+
$crate::Serialize::serialize(&self.0, serializer).await
453451
}
454452
}
455453
}
@@ -465,7 +463,7 @@ macro_rules! impl_serialize {
465463
serializer: &'fut mut dyn $crate::DynSerializer,
466464
) -> impl ::std::future::Future<Output = Result<(), $crate::MerdeError<'static>>> + 'fut {
467465
async move {
468-
self.0.serialize(serializer).await
466+
$crate::Serialize::serialize(&self.0, serializer).await
469467
}
470468
}
471469
}
@@ -488,7 +486,7 @@ macro_rules! impl_serialize {
488486
.await?;
489487
$(
490488
serializer.write($crate::Event::Str($crate::CowStr::Borrowed(stringify!($field)))).await?;
491-
self.$field.serialize(serializer).await?;
489+
$crate::Serialize::serialize(&self.$field, serializer).await?;
492490
)+
493491
serializer.write($crate::Event::MapEnd).await
494492
}
@@ -513,7 +511,7 @@ macro_rules! impl_serialize {
513511
.await?;
514512
$(
515513
serializer.write($crate::Event::Str($crate::CowStr::Borrowed(stringify!($field)))).await?;
516-
self.$field.serialize(serializer).await?;
514+
$crate::Serialize::serialize(&self.$field, serializer).await?;
517515
)*
518516
serializer.write($crate::Event::MapEnd).await
519517
}
@@ -533,17 +531,16 @@ macro_rules! impl_serialize {
533531
serializer: &'fut mut dyn $crate::DynSerializer,
534532
) -> impl ::std::future::Future<Output = Result<(), $crate::MerdeError<'static>>> + 'fut {
535533
async move {
536-
serializer
537-
.write($crate::Event::MapStart($crate::MapStart {
538-
size_hint: Some(1),
539-
}))
540-
.await?;
534+
$crate::Serialize::serialize(&$crate::Event::MapStart($crate::MapStart {
535+
size_hint: Some(1),
536+
}), serializer)
537+
.await?;
541538

542539
match self {
543540
$(
544541
Self::$variant(value) => {
545542
serializer.write($crate::Event::Str($crate::CowStr::Borrowed($variant_str))).await?;
546-
value.serialize(serializer).await?;
543+
$crate::Serialize::serialize(value, serializer).await?;
547544
}
548545
)*
549546
}
@@ -576,7 +573,7 @@ macro_rules! impl_serialize {
576573
$(
577574
Self::$variant(value) => {
578575
serializer.write($crate::Event::Str($crate::CowStr::Borrowed($variant_str))).await?;
579-
value.serialize(serializer).await?;
576+
$crate::Serialize::serialize(value, serializer).await?;
580577
}
581578
)+
582579
}

merde_core/src/serialize.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ impl<T: Serialize> Serialize for Vec<T> {
213213
}
214214
}
215215

216+
impl<T: Serialize> Serialize for Box<T> {
217+
async fn serialize<'se>(
218+
&'se self,
219+
serializer: &'se mut dyn DynSerializer,
220+
) -> Result<(), MerdeError<'static>> {
221+
(**self).serialize(serializer).await
222+
}
223+
}
224+
216225
impl<T: Serialize> Serialize for Arc<T> {
217226
async fn serialize<'se>(
218227
&'se self,

0 commit comments

Comments
 (0)