cargo Verified current stable Not installed? Package Management

Cargo / Add Dependency No Default Features

Add Dependency No Default Features

Includes a dependency without its default features in Cargo.toml.

$
Terminal
cargo add <dependency> --no-default-features

When To Use

When requiring only a subset of functionality from a dependency to minimize footprint.

Pro Tip

Use `--features` to manually include only the required features for precision and efficiency.

Terminal Output

Expected runtime feedback

Simulated preview
>
Output
$ cargo add serde --no-default-features

    Updating crates.io index
\ Updating serde v1.0.130 -> v1.0.130
    Adding dependency to Cargo.toml
    ```
    [dependencies]
    serde = { version = "1.0.130", default-features = false }
    ```

Anatomy of Output

Understanding the result

Added 'futures' v3.0.0 without default features. Dependency Added

Confirms successful addition without default features.

Updated Cargo.toml reflecting changes. Cargo.toml Updated

Indicates the modifications made.

Compiling futures v3.0.0... Compilation Process

Shows the status of ongoing dependency compilation.

Power User Variants

Optimized versions

cargo add futures --no-default-features

Add futures without any default functionality.

cargo add futures --no-default-features --features feature_a

Include specific features while excluding defaults.

Troubleshooting

Common pitfalls

error: 'futures' has no features available.

Solution: Check for available features in the documentation.

error: package not found in `Cargo.toml`.

Solution: Ensure the dependency is correctly specified.

error: failed to compile 'futures'.

Solution: Refer to compilation logs for specifics.

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.
<dependency>
dependency
The value supplied for dependency.
--no-default-features
Command Option
Tool-specific option used by this command invocation.

How To Run

Execution path

  1. Step 1

    Run the command: `cargo add serde --no-default-features`

  2. Step 2

    Check `Cargo.toml` to verify the dependency was added correctly.

Alternative Approaches

Comparable commands in other tools

Alternative package management tools for the same job.