aboutsummaryrefslogtreecommitdiff
path: root/src/deserializer
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-05-14 12:11:54 +0200
committerHampusM <hampus@hampusmat.com>2023-05-14 12:11:54 +0200
commit9588367284139266b55936d93428355cfa6de906 (patch)
tree6a189382758a86be3ac0a396e6d236fe91e65b1a /src/deserializer
parent1ffc8cbafc4439435307831e87d6f3c265ad819c (diff)
feat: add deserializer-static-generics conditional compilation macro
Diffstat (limited to 'src/deserializer')
-rw-r--r--src/deserializer/mod.rs44
1 files changed, 43 insertions, 1 deletions
diff --git a/src/deserializer/mod.rs b/src/deserializer/mod.rs
index 918136f..6a512dc 100644
--- a/src/deserializer/mod.rs
+++ b/src/deserializer/mod.rs
@@ -2,7 +2,7 @@
use std::convert::Infallible;
use crate::tagged::TagStart;
-use crate::util::trait_alias;
+use crate::util::{feature_alternate, trait_alias};
use crate::DeserializeTagged;
pub mod buffered;
@@ -278,3 +278,45 @@ macro_rules! impl_from_deserializer_error {
}
};
}
+
+feature_alternate!(
+ feature = "deserializer-static-generics",
+ /// Conditional compilation based on whether or not the `deserializer-static-generics`
+ /// feature is enabled.
+ ///
+ /// # Examples
+ /// ```
+ /// use std::io::Cursor;
+ ///
+ /// use xml_stinks::xml_stinks_if_deserializer_static_generics;
+ /// use xml_stinks::deserializer::buffered::Buffered as BufferedDeserializer;
+ /// use xml_stinks::deserializer::Deserializer;
+ ///
+ /// fn do_something(bytes: &[u8])
+ /// {
+ /// let deserializer = xml_stinks_if_deserializer_static_generics!(then {
+ /// BufferedDeserializer::new(Cursor::new(bytes.to_vec()));
+ /// } else {
+ /// // This wouldn't compile if the deserializer-static-generics feature was
+ /// // enabled
+ /// BufferedDeserializer::new(bytes);
+ /// });
+ ///
+ /// // ...
+ /// }
+ /// ```
+ when_enabled =
+ #[macro_export]
+ macro_rules! xml_stinks_if_deserializer_static_generics {
+ (then { $($then: tt)* }$(else { $($else: tt)* })?) => {
+ $($then)*
+ };
+ },
+ when_disabled =
+ #[macro_export]
+ macro_rules! xml_stinks_if_deserializer_static_generics {
+ (then { $($then: tt)* }$(else { $($else: tt)* })?) => {
+ $($($else)*)?
+ };
+ }
+);