xso: improve macro for FromXmlText/AsXmlText

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.
This commit is contained in:
Jonas Schäfer 2024-07-24 16:07:59 +02:00
parent 204c82e6b0
commit fe61a25cfd

View file

@ -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.")]