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
?
A feature gate is a high level tool to turn features on and off. It provides metadata about features, a simple, opinionated API, and avoid many potential pitfalls of other systems, such as using preferences directly.
Cargo "features" provide a mechanism to express conditional compilation and optional dependencies. A package defines a set of named features in the [features] table of Cargo. toml , and each feature can either be enabled or disabled.
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.
There are two types of attributes:
#
). They apply to the whole file only.#!
). 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 librariesIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With