I would like to enable a feature gate for my entire Cargo project. For example, I would like #![feature(non_ascii_idents)]
added to every source file. Is there a place to list them in Cargo.toml
?
Global feature gates in Cargo
1.5k views Asked by yong At
2
There are 2 answers
1
On
There are two types of attributes:
- file attributes (starting with
#
). They apply to the whole file only. - crate attributes (starting with
#!
). They apply to the whole crate at once.
What you want (#![feature(non_ascii_idents)]
) is a crate attribute, so you need to place it once at the top of the crate's main file. That main file is usually:
src/main.rs
for binariessrc/lib.rs
for libraries
No, though you don't add feature gates to every source file; they are crate attributes. That is, you set them on the crate, not on every module.