How to enable a feature


#1

Hello,

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:

...
[dependencies]

[features]
hello = []

I tried running the following commands:

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

and also:

rustc src/main.rs --features "hello"

But the output I get is always:

Feature disabled

What am I doing wrong?

Thanks!


#2

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


#3

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