Upgrade rust/crates/const_fn to 0.4.6

Test: make
Change-Id: I36ab38c6aad4a595a34f46019d170a33fb6153f4
26 files changed
tree: c33e9c5048109eae152e88eb76b4a978f2af98f2
  1. out/
  2. src/
  3. .cargo_vcs_info.json
  4. .gitignore
  5. Android.bp
  6. build.rs
  7. Cargo.toml
  8. Cargo.toml.orig
  9. CHANGELOG.md
  10. LICENSE-APACHE
  11. LICENSE-MIT
  12. METADATA
  13. MODULE_LICENSE_APACHE2
  14. OWNERS
  15. README.md
  16. TEST_MAPPING
README.md

#[const_fn]

crates.io docs.rs license rustc build status

An attribute for easy generation of const functions with conditional compilations.

Usage

Add this to your Cargo.toml:

[dependencies]
const_fn = "0.4"

Compiler support: requires rustc 1.31+

Examples

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() {
    /* ... */
}

Alternatives

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)

License

Licensed under either of Apache License, Version 2.0 or MIT license 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.