xso: improve macro for FromXmlText/AsXmlText
Jonas Schäfer
created 2 years ago
Now it's not limited to a single feature gate per type (or even just
feature gates: it should now also be possible to add constraints
based on OS, for example) anymore.
Change summary
xso/src/text.rs | 14 +++++---------
1 file changed, 5 insertions(+), 9 deletions(-)
Detailed changes
@@ -15,17 +15,13 @@ use crate::{error::Error, AsXmlText, FromXmlText};
#[cfg(feature = "base64")]
use base64::engine::{general_purpose::STANDARD as StandardBase64Engine, Engine as _};
-#[cfg(feature = "jid")]
-use jid;
-#[cfg(feature = "uuid")]
-use uuid;
macro_rules! convert_via_fromstr_and_display {
- ($($(#[cfg(feature = $feature:literal)])?$t:ty,)+) => {
+ ($($(#[cfg $cfg:tt])?$t:ty,)+) => {
$(
$(
- #[cfg(feature = $feature)]
- #[cfg_attr(docsrs, doc(cfg(feature = $feature)))]
+ #[cfg $cfg]
+ #[cfg_attr(docsrs, doc(cfg $cfg))]
)?
impl FromXmlText for $t {
#[doc = concat!("Parse [`", stringify!($t), "`] from XML text via [`FromStr`][`core::str::FromStr`].")]
@@ -35,8 +31,8 @@ macro_rules! convert_via_fromstr_and_display {
}
$(
- #[cfg(feature = $feature)]
- #[cfg_attr(docsrs, doc(cfg(feature = $feature)))]
+ #[cfg $cfg]
+ #[cfg_attr(docsrs, doc(cfg $cfg))]
)?
impl AsXmlText for $t {
#[doc = concat!("Convert [`", stringify!($t), "`] to XML text via [`Display`][`core::fmt::Display`].\n\nThis implementation never fails.")]