https://github.com/sunsided/feature-gate
A simple macro for feature-gating modules and types
https://github.com/sunsided/feature-gate
procedural-macro rust
Last synced: about 1 year ago
JSON representation
A simple macro for feature-gating modules and types
- Host: GitHub
- URL: https://github.com/sunsided/feature-gate
- Owner: sunsided
- License: eupl-1.2
- Created: 2023-05-29T16:03:07.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-29T16:07:59.000Z (about 3 years ago)
- Last Synced: 2025-04-07T03:47:51.704Z (over 1 year ago)
- Topics: procedural-macro, rust
- Language: Rust
- Homepage: https://crates.io/crates/feature-gate
- Size: 11.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# 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](https://docs.rs/about/metadata)):
```toml
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
```
## Example
The `feature_gate` macro allows the specification of a single feature:
```rust
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:
```rust
use feature_gate::feature_gate_ex;
#[feature_gate_ex(any(test, feature = "test"))]
struct FeatureGated;
#[test]
fn it_works() {
let _ = FeatureGated {};
}
```