问题
Rust has the ability to check configuration at build time with, e.g., #[cfg(target_os = "linux")] or if cfg!(target_os = "linux") {...}, where target_os is a feature.
Is there a list of all (or, at least, commonly used) features that can be checked in Rust?
See related question regarding attributes Is there an exhaustive list of standard attributes anywhere?.
回答1:
The "Conditional compilation" section of the Reference has a list of configurations that must be defined (as of Rust 1.14):
target_archwith values like:x86x86_64mipspowerpcpowerpc64armaarch64
target_oswith values like:windowsmacosioslinuxandroidfreebsddragonflybitrigopenbsdnetbsd
target_familywith values like:unixwindows
unix(shortcut fortarget_family)windows(shortcut fortarget_family)target_envwith values like:gnumsvcmusl""(empty string)
target_endianwith values:littlebig
target_pointer_widthwith values like:3264
target_has_atomicwith values like:8163264ptr
target_vendorwith values like:applepcunknown
testdebug_assertions
回答2:
You can also use this command: rustc --print target-list.
Each triple are formatted as follows: {arch}-{vendor}-{sys}-{abi}.
For example, the triple 'arm-unknown-linux-gnueabihf' refers to:
- architecture: arm
- vendor: unknown. In this case, no vendor was specified.
- system: linux
- ABI: gnueabihf
回答3:
See also https://internals.rust-lang.org/t/all-the-rust-features/4322 for a comprehensive list of features.
Bear in mind that some / most of the features won't be stabilized so will only be available in nightly for some time and are subject to breaking improvements / upgrades until they are either stabilized or discontinued.
Features in rust nightly is survival of the fittest.
来源:https://stackoverflow.com/questions/41742046/is-there-a-list-of-all-cfg-features