Skip to content

Add dependency of examples towards features #1570

Closed
@tomaka

Description

@tomaka

Cargo should allow writing:

[package]
# ...

[features]
a = []

[example]
src = "examples/example-that-uses-a.rs"
features = ["a"]

example-that-uses-a would only be compiled if you call cargo test --features "a".
More formally, examples should have the possibiliy to declare a list of features that must be enabled for this example to be compiled.

The motivation is to avoid having to write ugly code like this one.
Newcomers often copy-paste a library's examples to get started, and don't necessarly understand what the #![cfg(feature)] thing is and that they shouldn't copy it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-featuresArea: features — conditional compilation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions