cargo Verified current stable Not installed? Build Tools

Cargo / Activate Features

Activate Features

Enables specified features for a Cargo project at runtime.

$
Terminal
cargo r -F "<feature1 feature2 ...>"

When To Use

When needing to test specific functionalities gated by feature flags during development.

Pro Tip

Utilize `--no-default-features` to deactivate default features while selectively activating others for granular control.

Command Builder

Tune the command before you copy it

Back to syntax
$
Generated Command
cargo r -F "<feature1 feature2 ...>"

Terminal Output

Expected runtime feedback

Simulated preview
>
Output
Activating features for my_project...

Features activated:
  feature1
  feature2

Running my_project with activated features...

Anatomy of Output

Understanding the result

Activating features: feature_a feature_b... Features Activation Notice

Confirms activation of specified features.

info: succeeded without errors. Execution Summary

Indicates successful activation and run.

error: unknown feature flags provided Unknown Feature Warning

Indicates that some specified features do not exist.

Power User Variants

Optimized versions

cargo run --features "feature_a feature_b"

Activate multiple features for testing.

cargo run --no-default-features --features "custom_feature"

Exclude default features while activating custom functionality.

cargo run --features "feature_1" --verbose

Run with debugging information for enabled features.

Troubleshooting

Common pitfalls

error: feature `feature_name` does not exist

Solution: Ensure the feature is defined in `Cargo.toml` under `[features]`.

error: invalid combination of features activated

Solution: Review feature dependencies for conflicts.

error: expected at least one feature but found none

Solution: Check that features are provided correctly in the command.

Command Breakdown

What each part is doing

cargo
Base Command
The executable that performs this operation. Here it runs Cargo before the shell applies any redirect operators.
r
r|run
The value supplied for r|run.
-F
F| features
The value supplied for F| features.
<feature1 feature2 ...>
feature1 feature2 ...
The value supplied for feature1 feature2 ....
-F
Command Option
Tool-specific option used by this command invocation.

How To Run

Execution path

  1. Step 1

    Run the command: cargo run --features "feature1 feature2"

  2. Step 2

    Check the output to verify if features are activated successfully.

Alternative Approaches

Comparable commands in other tools

Alternative build tools tools for the same job.