From 5da4e62024086f6f1e3e9718be6d9fea141142a0 Mon Sep 17 00:00:00 2001 From: Amos Wenger Date: Sat, 30 Nov 2024 18:34:19 +0100 Subject: [PATCH] Remove workaround for https://github.com/rust-lang/rust/issues/133676 --- merde_core/src/deserialize.rs | 18 ++- merde_core/src/lib.rs | 3 - merde_core/src/serialize.rs | 238 +++++++++++++++------------------- merde_core/src/time.rs | 10 +- 4 files changed, 124 insertions(+), 145 deletions(-) diff --git a/merde_core/src/deserialize.rs b/merde_core/src/deserialize.rs index 06b6123..735b46f 100644 --- a/merde_core/src/deserialize.rs +++ b/merde_core/src/deserialize.rs @@ -49,7 +49,9 @@ where pub trait DynDeserializerExt<'s> { fn t<'de, T: Deserialize<'s>>( &'de mut self, - ) -> impl Future>> + 'de; + ) -> impl Future>> + 'de + where + 's: 'de; fn deserialize>(&mut self) -> Result>; @@ -60,12 +62,13 @@ impl<'s, D> DynDeserializerExt<'s> for D where D: Deserializer<'s>, { - // cf. - #[allow(clippy::manual_async_fn)] fn t<'de, T: Deserialize<'s>>( &'de mut self, - ) -> impl Future>> + 'de { - async move { T::deserialize(self).await } + ) -> impl Future>> + 'de + where + 's: 'de, + { + T::deserialize(self) } fn deserialize>(&mut self) -> Result> { @@ -80,7 +83,10 @@ where impl<'s> DynDeserializerExt<'s> for dyn DynDeserializer<'s> + '_ { fn t<'de, T: Deserialize<'s>>( &'de mut self, - ) -> impl Future>> + 'de { + ) -> impl Future>> + 'de + where + 's: 'de, + { T::deserialize(self) } diff --git a/merde_core/src/lib.rs b/merde_core/src/lib.rs index d642ba5..7211b49 100644 --- a/merde_core/src/lib.rs +++ b/merde_core/src/lib.rs @@ -1,6 +1,3 @@ -// cf. -#![allow(clippy::manual_async_fn)] - mod cowstr; pub use cowstr::CowStr; diff --git a/merde_core/src/serialize.rs b/merde_core/src/serialize.rs index 0479960..8d9ec7a 100644 --- a/merde_core/src/serialize.rs +++ b/merde_core/src/serialize.rs @@ -91,11 +91,11 @@ macro_rules! impl_trivial_serialize { ($ty:ty) => { impl Serialize for $ty { - fn serialize<'fut>( + async fn serialize<'fut>( &'fut self, serializer: &'fut mut dyn DynSerializer, - ) -> impl Future>> + 'fut { - async { serializer.write(Event::from(*self)).await } + ) -> Result<(), MerdeError<'static>> { + serializer.write(Event::from(*self)).await } } }; @@ -115,197 +115,177 @@ impl_trivial_serialize! { } impl Serialize for String { - fn serialize<'se>( + async fn serialize<'se>( &'se self, serializer: &'se mut dyn DynSerializer, - ) -> impl Future>> + 'se { - async { serializer.write(Event::Str(CowStr::Borrowed(self))).await } + ) -> Result<(), MerdeError<'static>> { + serializer.write(Event::Str(CowStr::Borrowed(self))).await } } impl<'s> Serialize for &'s str { - fn serialize<'se>( + async fn serialize<'se>( &'se self, serializer: &'se mut dyn DynSerializer, - ) -> impl Future>> + 'se { - async { serializer.write(Event::Str(CowStr::Borrowed(self))).await } + ) -> Result<(), MerdeError<'static>> { + serializer.write(Event::Str(CowStr::Borrowed(self))).await } } impl<'s> Serialize for CowStr<'s> { - fn serialize<'se>( + async fn serialize<'se>( &'se self, serializer: &'se mut dyn DynSerializer, - ) -> impl Future>> + 'se { - async { - serializer - .write(Event::Str(CowStr::Borrowed(self.as_ref()))) - .await - } + ) -> Result<(), MerdeError<'static>> { + serializer + .write(Event::Str(CowStr::Borrowed(self.as_ref()))) + .await } } impl<'s> Serialize for Cow<'s, str> { - fn serialize<'se>( + async fn serialize<'se>( &'se self, serializer: &'se mut dyn DynSerializer, - ) -> impl Future>> + 'se { - async { - serializer - .write(Event::Str(CowStr::Borrowed(self.as_ref()))) - .await - } + ) -> Result<(), MerdeError<'static>> { + serializer + .write(Event::Str(CowStr::Borrowed(self.as_ref()))) + .await } } impl<'s> Serialize for CowBytes<'s> { - fn serialize<'se>( + async fn serialize<'se>( &'se self, serializer: &'se mut dyn DynSerializer, - ) -> impl Future>> + 'se { - async { - serializer - .write(Event::Bytes(CowBytes::Borrowed(self.as_ref()))) - .await - } + ) -> Result<(), MerdeError<'static>> { + serializer + .write(Event::Bytes(CowBytes::Borrowed(self.as_ref()))) + .await } } impl Serialize for Option { - fn serialize<'se>( + async fn serialize<'se>( &'se self, serializer: &'se mut dyn DynSerializer, - ) -> impl Future>> + 'se { - async move { - match self { - Some(value) => value.serialize(serializer).await, - None => serializer.write(Event::Null).await, - } + ) -> Result<(), MerdeError<'static>> { + match self { + Some(value) => value.serialize(serializer).await, + None => serializer.write(Event::Null).await, } } } impl Serialize for &[T] { - fn serialize<'se>( + async fn serialize<'se>( &'se self, serializer: &'se mut dyn DynSerializer, - ) -> impl Future>> + 'se { - async { - serializer - .write(Event::ArrayStart(ArrayStart { - size_hint: Some(self.len()), - })) - .await?; - for item in *self { - item.serialize(serializer).await?; - } - serializer.write(Event::ArrayEnd).await + ) -> Result<(), MerdeError<'static>> { + serializer + .write(Event::ArrayStart(ArrayStart { + size_hint: Some(self.len()), + })) + .await?; + for item in *self { + item.serialize(serializer).await?; } + serializer.write(Event::ArrayEnd).await } } impl Serialize for Vec { - fn serialize<'se>( + async fn serialize<'se>( &'se self, serializer: &'se mut dyn DynSerializer, - ) -> impl Future>> + 'se { - async move { - serializer - .write(Event::ArrayStart(ArrayStart { - size_hint: Some(self.len()), - })) - .await?; - for item in self { - item.serialize(serializer).await?; - } - serializer.write(Event::ArrayEnd).await + ) -> Result<(), MerdeError<'static>> { + serializer + .write(Event::ArrayStart(ArrayStart { + size_hint: Some(self.len()), + })) + .await?; + for item in self { + item.serialize(serializer).await?; } + serializer.write(Event::ArrayEnd).await } } impl Serialize for HashMap { - fn serialize<'fut>( + async fn serialize<'fut>( &'fut self, serializer: &'fut mut dyn DynSerializer, - ) -> impl Future>> + 'fut { - async move { - serializer - .write(Event::MapStart(MapStart { - size_hint: Some(self.len()), - })) - .await?; - for (key, value) in self { - key.serialize(serializer).await?; - value.serialize(serializer).await?; - } - serializer.write(Event::MapEnd).await + ) -> Result<(), MerdeError<'static>> { + serializer + .write(Event::MapStart(MapStart { + size_hint: Some(self.len()), + })) + .await?; + for (key, value) in self { + key.serialize(serializer).await?; + value.serialize(serializer).await?; } + serializer.write(Event::MapEnd).await } } impl Serialize for Map<'_> { - fn serialize<'se>( + async fn serialize<'se>( &'se self, serializer: &'se mut dyn DynSerializer, - ) -> impl Future>> + 'se { - async { - serializer - .write(Event::MapStart(MapStart { - size_hint: Some(self.len()), - })) - .await?; - for (key, value) in self.iter() { - serializer.write(Event::Str(CowStr::Borrowed(key))).await?; - value.serialize(serializer).await?; - } - serializer.write(Event::MapEnd).await + ) -> Result<(), MerdeError<'static>> { + serializer + .write(Event::MapStart(MapStart { + size_hint: Some(self.len()), + })) + .await?; + for (key, value) in self.iter() { + serializer.write(Event::Str(CowStr::Borrowed(key))).await?; + value.serialize(serializer).await?; } + serializer.write(Event::MapEnd).await } } impl Serialize for Array<'_> { - fn serialize<'se>( + async fn serialize<'se>( &'se self, serializer: &'se mut dyn DynSerializer, - ) -> impl Future>> + 'se { - async { - serializer - .write(Event::ArrayStart(ArrayStart { - size_hint: Some(self.len()), - })) - .await?; - for item in self.iter() { - item.serialize(serializer).await?; - } - serializer.write(Event::ArrayEnd).await + ) -> Result<(), MerdeError<'static>> { + serializer + .write(Event::ArrayStart(ArrayStart { + size_hint: Some(self.len()), + })) + .await?; + for item in self.iter() { + item.serialize(serializer).await?; } + serializer.write(Event::ArrayEnd).await } } impl Serialize for Value<'_> { - fn serialize<'se>( + async fn serialize<'se>( &'se self, serializer: &'se mut dyn DynSerializer, - ) -> impl Future>> + 'se { - async move { - match self { - Value::I64(i) => serializer.write(Event::I64(*i)).await, - Value::U64(u) => serializer.write(Event::U64(*u)).await, - Value::Float(f) => serializer.write(Event::F64(f.into_inner())).await, - Value::Str(s) => serializer.write(Event::Str(s.clone())).await, - Value::Bytes(b) => serializer.write(Event::Bytes(b.clone())).await, - Value::Null => serializer.write(Event::Null).await, - Value::Bool(b) => serializer.write(Event::Bool(*b)).await, - Value::Array(arr) => { - arr.serialize(serializer) - .with_metastack_resume_point() - .await - } - Value::Map(map) => { - map.serialize(serializer) - .with_metastack_resume_point() - .await - } + ) -> Result<(), MerdeError<'static>> { + match self { + Value::I64(i) => serializer.write(Event::I64(*i)).await, + Value::U64(u) => serializer.write(Event::U64(*u)).await, + Value::Float(f) => serializer.write(Event::F64(f.into_inner())).await, + Value::Str(s) => serializer.write(Event::Str(s.clone())).await, + Value::Bytes(b) => serializer.write(Event::Bytes(b.clone())).await, + Value::Null => serializer.write(Event::Null).await, + Value::Bool(b) => serializer.write(Event::Bool(*b)).await, + Value::Array(arr) => { + arr.serialize(serializer) + .with_metastack_resume_point() + .await + } + Value::Map(map) => { + map.serialize(serializer) + .with_metastack_resume_point() + .await } } } @@ -314,18 +294,16 @@ impl Serialize for Value<'_> { macro_rules! impl_serialize_for_tuple { ($($type_arg:ident),*) => { impl<$($type_arg: Serialize),*> Serialize for ($($type_arg),*,) { - fn serialize<'se>( + async fn serialize<'se>( &'se self, serializer: &'se mut dyn DynSerializer, - ) -> impl Future>> + 'se { - async move { - serializer.write(Event::ArrayStart(ArrayStart { - size_hint: Some(count_tup!($($type_arg)*)) - })).await?; - - impl_serialize_for_tuple!(@inner self serializer _field => _field () ($($type_arg)*)); - serializer.write(Event::ArrayEnd).await - } + ) -> Result<(), MerdeError<'static>> { + serializer.write(Event::ArrayStart(ArrayStart { + size_hint: Some(count_tup!($($type_arg)*)) + })).await?; + + impl_serialize_for_tuple!(@inner self serializer _field => _field () ($($type_arg)*)); + serializer.write(Event::ArrayEnd).await } } }; diff --git a/merde_core/src/time.rs b/merde_core/src/time.rs index 8c19a9f..4e496d0 100644 --- a/merde_core/src/time.rs +++ b/merde_core/src/time.rs @@ -125,14 +125,12 @@ mod tests { } impl Serializer for Journal { - fn write<'fut>( + async fn write<'fut>( &'fut mut self, event: Event<'fut>, - ) -> impl Future>> + 'fut { - async move { - self.events.push_back(event.into_static()); - Ok(()) - } + ) -> Result<(), MerdeError<'static>> { + self.events.push_back(event.into_static()); + Ok(()) } }