diff options
Diffstat (limited to 'src/deserializer/mod.rs')
-rw-r--r-- | src/deserializer/mod.rs | 44 |
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)*)? + }; + } +); |