[go: up one dir, main page]

const_fn 0.4.1

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

#[const_fn]

crates-badge docs-badge license-badge rustc-badge

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

Usage

Add this to your Cargo.toml:

[dependencies]
const_fn = "0.4"

The current const_fn requires Rust 1.31 or later.

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

License

Licensed under either of

at your option.

Contribution

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.