Crate feature_scope

Source
Expand description

§feature-scope Macros

Procedural macros for the feature-scope library that enables workspace crates to independently control their required features without cross-package interference.

§Overview

This crate provides the #[feature_scope] and #[feature_scope_default] attribute macros that allow you to conditionally compile code based on feature flags defined in your Cargo.toml.

§Configuration

This library uses a two-step configuration approach:

  1. Declare features in library crates using package.metadata.feature-scope-decl:
# In your library crate's Cargo.toml
[package.metadata.feature-scope-decl]
default = ["a"]
a = []
b = []
c = []
  1. Configure feature usage in consumer crates using package.metadata.feature-scope:
# In your binary/consumer crate's Cargo.toml
[[package.metadata.feature-scope]]
package = "your-library-name"
features = ["b"]
default-features = false

§Usage

Use the macros in your library code:

use feature_scope::{feature_scope, feature_scope_default};

#[feature_scope_default(a)]
pub fn feature_a_function() {
    println!("This compiles when feature 'a' is enabled or by default");
}

#[feature_scope(b)]
pub fn feature_b_function() {
    println!("This only compiles when feature 'b' is enabled");
}

#[feature_scope_default]
pub fn default_function() {
    println!("This compiles by default");
}

§Build Commands

Use cargo feature-scope commands instead of regular cargo commands to build your project:

cargo feature-scope build
cargo feature-scope run
cargo feature-scope test

Attribute Macros§

feature_scope
feature_scope_default