#proc-macro #template

macro feature-gate

A simple macro for feature-gating modules and types

2 releases

0.1.1 May 29, 2023
0.1.0 May 29, 2023

#842 in Procedural macros

Custom license

8KB

Simple documented feature gates

This crates provides the feature_gate and feature_gate_ex macros for simple #[cfg(feature = "...")] macros that are properly documented on docs.rs.

Stable Rust

Note that for it to work properly on stable Rust, the following needs to be added to Cargo.toml for the time being (see Metadata for custom builds):

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

Example

The feature_gate macro allows the specification of a single feature:

use feature_gate::feature_gate;

#[feature_gate("test")]
struct FeatureGated;

#[test]
fn it_works() {
    let _ = FeatureGated {};
}

The feature_gate_ex macro allows the specification of a complex set of requirements:

use feature_gate::feature_gate_ex;

#[feature_gate_ex(any(test, feature = "test"))]
struct FeatureGated;

#[test]
fn it_works() {
    let _ = FeatureGated {};
}

lib.rs:

Simple documented feature gates

This crates provides the feature_gate and feature_gate_ex macros for simple #[cfg(feature = "...")] macros that are properly documented on docs.rs.

Stable Rust

Note that for it to work properly on stable Rust, the following needs to be added to Cargo.toml for the time being (see Metadata for custom builds):

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

Example

The feature_gate macro allows the specification of a single feature:

use feature_gate::feature_gate;

#[feature_gate("test")]
struct FeatureGated;

#[test]
fn it_works() {
    let _ = FeatureGated {};
}

The feature_gate_ex macro allows the specification of a complex set of requirements:

use feature_gate::feature_gate_ex;

#[feature_gate_ex(any(test, feature = "test"))]
struct FeatureGated;

#[test]
fn it_works() {
    let _ = FeatureGated {};
}

Dependencies

~250–700KB
~17K SLoC