cfg_attrs 1.0.2

An alternative to #[cfg_attr(...)] that is easier to use with doc comments.
Documentation

WARNING

This project is archived because it turns out that using this attribute will place doc comments using it before all other doc comments 100% of the time. This is not something that can be changed, because it's how attribute proc macros work.

#[cfg_attrs(...)]

Provides an alternative syntax to #[cfg_attr(...)] that is easier to use with doc comments.

Syntax
CfgAttrsAttribute :
cfg_attrs ( ConfigurationPredicate , CfgAttrs )

CfgAttrs :
{ Attributes } | Attributes

Attributes :
OuterAttribute* ( , OuterAttribute* )* ,?

Examples

/// This is an example struct.
#[cfg_attrs(
    debug_assertions,
    ///
    /// Hello! These are docs that only appear when
    /// debug assertions are active.
)]
struct Example;

This can also be written as:

/// This is an example struct.
#[cfg_attrs(debug_assertions, {
    ///
    /// Hello! These are docs that only appear when
    /// debug assertions are active.
})]
struct Example;

Either of these will expand to the following usage of #[cfg_attr(...)]:

/// This is an example struct.
#[cfg_attr(
    debug_assertions,
    doc = "",
    doc = " Hello! These are docs that only appear when",
    doc = " debug assertions are active."
)]
struct Example;

Which, if debug assertions are active, would be expanded to:

/// This is an example struct.
///
/// Hello! These are docs that only appear when
/// debug assertions are active.
struct Example;

#[cfg_attrs(...)] may also be used with attributes other than doc comments, though there is little advantage over using #[cfg_attr(...)] in these cases:

#[cfg_attrs(
    feature = "magic",
    #[sparkles]
    #[crackles]
)]
fn bewitched() {}

With that example being equivalent to:

#[cfg_attr(feature = "magic", sparkles, crackles)]
fn bewitched() {}