aboutsummaryrefslogtreecommitdiff
path: root/src/deserializer/mod.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-05-09 20:38:46 +0200
committerHampusM <hampus@hampusmat.com>2023-05-11 21:05:53 +0200
commit8818a94ad79ebdebdf4c7819bd42e363c63bd630 (patch)
tree0a757ff271bf9d4d15be1a3a947f58b613961cbf /src/deserializer/mod.rs
parente762babd9e69400ccd178ba8946168640093eb63 (diff)
feat: add optional deserializer generics static bounds
Diffstat (limited to 'src/deserializer/mod.rs')
-rw-r--r--src/deserializer/mod.rs35
1 files changed, 29 insertions, 6 deletions
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<Output, Err, DeserializeFn>(
+ fn de_tag_with<Output, Err, Func>(
&mut self,
tag_name: &str,
ignore_end: IgnoreEnd,
- deserialize: DeserializeFn,
+ deserialize: Func,
) -> Result<Output, Error<Err>>
where
+ Output: MaybeStatic,
Err: std::error::Error + Send + Sync + 'static,
- DeserializeFn: FnOnce(&TagStart, &mut Self) -> Result<Output, Err>;
+ Func: FnOnce(&TagStart, &mut Self) -> Result<Output, Err> + MaybeStatic;
/// Deserializes a list of tagged elements.
///
/// # Errors
/// Returns `Err` if deserialization fails.
- fn de_tag_list<De: DeserializeTagged>(
+ fn de_tag_list<De, TagName>(
&mut self,
- tag_name: Option<&str>,
- ) -> Result<Vec<De>, Error<De::Error>>;
+ tag_name: Option<TagName>,
+ ) -> Result<Vec<De>, Error<De::Error>>
+ where
+ De: DeserializeTagged,
+ TagName: AsRef<str> + MaybeStatic;
/// Deserializes a text element.
///
@@ -63,6 +68,24 @@ pub trait Deserializer
fn skip_to_tag_end(&mut self, tag_name: &str) -> Result<(), Error<Infallible>>;
}
+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`**.