commit | b3b422d2500290b6459af803c74754dee9355c3a | [log] [tgz] |
---|---|---|
author | Chih-Hung Hsieh <chh@google.com> | Wed Oct 21 01:51:27 2020 -0700 |
committer | Chih-Hung Hsieh <chh@google.com> | Sun Oct 25 18:17:19 2020 -0700 |
tree | d08e5f45af0d406ffc08c1e43e5b29ec97d2056a | |
parent | fcfc9e618c6ba5265a91c242fb68343218fd5b61 [diff] |
Add Android.bp with --copy-out flag. Bug: 169611678 Bug: 171659849 Test: make Test: tools/external_updater/updater.sh update --refresh --keep-date rust/crates/const_fn Change-Id: I20c22072515a3b2fcd9f1e6e71ac99d5cf6e8e6a
An attribute for easy generation of const functions with conditional compilations.
Add this to your Cargo.toml
:
[dependencies] const_fn = "0.4"
The current const_fn requires Rust 1.31 or later.
use const_fn::const_fn; // function is `const` on specified version and later compiler (including beta and nightly) #[const_fn("1.36")] pub const fn version() { /* ... */ } // function is `const` on nightly compiler (including dev build) #[const_fn(nightly)] pub const fn nightly() { /* ... */ } // function is `const` if `cfg(...)` is true #[const_fn(cfg(...))] pub const fn cfg() { /* ... */ } // function is `const` if `cfg(feature = "...")` is true #[const_fn(feature = "...")] pub const fn feature() { /* ... */ }
This crate is proc-macro, but is very lightweight, and has no dependencies.
You can manually define declarative macros with similar functionality (see if_rust_version
), or you can define the same function twice with different cfg. (Note: the former approach requires more macros to be defined depending on the number of version requirements, the latter approach requires more functions to be maintained manually)
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.