From 8818a94ad79ebdebdf4c7819bd42e363c63bd630 Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 9 May 2023 20:38:46 +0200 Subject: feat: add optional deserializer generics static bounds --- src/deserializer/mod.rs | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'src/deserializer/mod.rs') diff --git a/src/deserializer/mod.rs b/src/deserializer/mod.rs index bd0c0e4..e0c5f6d 100644 --- a/src/deserializer/mod.rs +++ b/src/deserializer/mod.rs @@ -2,6 +2,7 @@ use std::convert::Infallible; use crate::tagged::TagStart; +use crate::util::trait_alias; use crate::DeserializeTagged; pub mod buffered; @@ -23,24 +24,28 @@ pub trait Deserializer /// /// # Errors /// Returns `Err` if deserialization fails. - fn de_tag_with( + fn de_tag_with( &mut self, tag_name: &str, ignore_end: IgnoreEnd, - deserialize: DeserializeFn, + deserialize: Func, ) -> Result> where + Output: MaybeStatic, Err: std::error::Error + Send + Sync + 'static, - DeserializeFn: FnOnce(&TagStart, &mut Self) -> Result; + Func: FnOnce(&TagStart, &mut Self) -> Result + MaybeStatic; /// Deserializes a list of tagged elements. /// /// # Errors /// Returns `Err` if deserialization fails. - fn de_tag_list( + fn de_tag_list( &mut self, - tag_name: Option<&str>, - ) -> Result, Error>; + tag_name: Option, + ) -> Result, Error> + where + De: DeserializeTagged, + TagName: AsRef + MaybeStatic; /// Deserializes a text element. /// @@ -63,6 +68,24 @@ pub trait Deserializer fn skip_to_tag_end(&mut self, tag_name: &str) -> Result<(), Error>; } +macro_rules! maybe_static_doc { + () => { + "Bound to `'static` if the `deserializer-static-generics` feature is enabled." + }; +} + +#[cfg(any(not(feature = "deserializer-static-generics"), doc))] +trait_alias! { + #[doc = maybe_static_doc!()] + pub MaybeStatic; +} + +#[cfg(all(feature = "deserializer-static-generics", not(doc)))] +trait_alias! { + #[doc = maybe_static_doc!()] + pub MaybeStatic: 'static; +} + /// Whether or not to skip the end tag of a tagged element. /// /// **Should be `No`**. -- cgit v1.2.3-18-g5258