Enable feature for an example

Is it possible to enable a feature for an example ?
I tried this, but it's not working:

[[example]]
name = "simple"
features = ["my_feature"]

I know it's possible to do cargo run --example simple --features my_feature. But since I'm using VSCode, I need to specified the feature is always enabled for this example.

I had exactly this issue just recently and I couldn't find a solution. I think it's not possible unless you add it as a default feature of your crate. But I'm happy to be wrong about it.

I created a post on the internal forum to propose to being able to enable feature for example:

There is a required-features key that doesn't enable the feature but, it displays an error message if the feature isn't enabled by the user.
Also, VSCode plugin can detects that.

1 Like