How to enable a feature


I am trying to enable a feature in a dummy program and can't seem to get it working.

I have the following code:

fn main() {
    if cfg!(features = "hello") {
        println!("Feature enabled");
    } else {
        println!("Feature disabled");

My Cargo.toml is the following:


hello = []

I tried running the following commands:

cargo build --features "hello"
cargo run --features "hello"

and also:

rustc src/ --features "hello"

But the output I get is always:

Feature disabled

What am I doing wrong?


It's feature = "hello". Singular, not plural.

1 Like

Thank you for the quick answer!
I knew I was missing something obvious. It works, thanks a lot!