---
source: https://iinventedlight.com/library/notes/rust-cargo-features.md
title: "Cargo features are named flags in Cargo.toml that enable optional compilation"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT OR Apache-2.0 (The Cargo Book); MIT OR Apache-2.0 (rust-lang/cargo (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Cargo Book, Features, MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/cargo/master/LICENSE-MIT, https://raw.githubusercontent.com/rust-lang/cargo/master/LICENSE-APACHE). Copyright (c) The Rust Project Developers; rust-lang/cargo (GitHub), features.md (The Cargo Book source), MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/cargo/master/LICENSE-MIT, https://raw.githubusercontent.com/rust-lang/cargo/master/LICENSE-APACHE). Copyright (c) The Rust Project Developers."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-17
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-17
as_of: 2026-11-17
confidence: medium
untested: "Not reproduced (2026-11-17). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: Cargo features"
tags: [rust, cargo, features, cfg, optional-dependencies]
client: Librarian
sources:
  - id: S1
    title: "Features"
    publisher: The Cargo Book
    url: https://doc.rust-lang.org/cargo/reference/features.html
    accessed: 2026-11-17
    license: "MIT OR Apache-2.0"
  - id: S2
    title: "features.md (The Cargo Book source)"
    publisher: rust-lang/cargo (GitHub)
    url: https://github.com/rust-lang/cargo/blob/master/doc/book/src/reference/features.md
    accessed: 2026-11-17
    license: "MIT OR Apache-2.0"
---
# Cargo features are named flags in Cargo.toml that enable optional compilation
**Answer:** Cargo features are named flags you define in the `[features]` table of `Cargo.toml`. Each feature is either enabled or disabled. Features of the package being built can be turned on with command-line flags such as `--features`. Features of dependencies are enabled in the dependency declaration.

## What a feature enables

A feature lists other features or optional dependencies that it turns on. In code, gate a module with `#[cfg(feature = "webp")]`. Cargo passes these to `rustc` with `--cfg`, and you can test them with the `cfg` attribute or the `cfg` macro.

Building the package turns on the `default` feature, which then enables the features it lists. Use the `--no-default-features` command-line flag to disable the package's default features. In a dependency declaration, set `default-features = false`. Dependencies turn default features on automatically unless that option is set.

## See also

- [rust-cargo-new-project](https://iinventedlight.com/library/notes/rust-cargo-new-project/)
- [rust-packages-crates-modules](https://iinventedlight.com/library/notes/rust-packages-crates-modules/)
- [rust-cargo-build-scripts](https://iinventedlight.com/library/notes/rust-cargo-build-scripts/)
- [rust-cargo-test-options](https://iinventedlight.com/library/notes/rust-cargo-test-options/)

## Claims

- id: C1
  claim: Features are defined in the [features] table of Cargo.toml.
  source: S1
  evidence: "named features in the [features] table of Cargo.toml"

- id: C2
  claim: Package features can be enabled on the command line with --features.
  source: S1
  evidence: "enabled on the command-line with flags such as --features"

- id: C3
  claim: A feature lists other features or optional dependencies it enables.
  source: S2
  evidence: "other features or optional dependencies that it enables"

- id: C4
  claim: The default feature is enabled when the package is built.
  source: S2
  evidence: "the `default` feature is enabled which in turn"

## Sources

- [S1] Features. The Cargo Book. https://doc.rust-lang.org/cargo/reference/features.html . License: MIT OR Apache-2.0. Accessed 2026-11-17.

- [S2] features.md (The Cargo Book source). rust-lang/cargo (GitHub). https://github.com/rust-lang/cargo/blob/master/doc/book/src/reference/features.md . License: MIT OR Apache-2.0. Accessed 2026-11-17.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Cargo Book, Features, MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/cargo/master/LICENSE-MIT, https://raw.githubusercontent.com/rust-lang/cargo/master/LICENSE-APACHE). Copyright (c) The Rust Project Developers; rust-lang/cargo (GitHub), features.md (The Cargo Book source), MIT OR Apache-2.0 (https://raw.githubusercontent.com/rust-lang/cargo/master/LICENSE-MIT, https://raw.githubusercontent.com/rust-lang/cargo/master/LICENSE-APACHE). Copyright (c) The Rust Project Developers. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
