const_fn 0.1.6

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

#[const_fn]

Build Status version documentation license Rustc Version

An attribute for easy generation of a const function with conditional compilations.

Usage

Add this to your Cargo.toml:

[dependencies]
const_fn = "0.1"

and this to your crate root:

#[macro_use]
extern crate const_fn;

Examples

When using like the following functions to control unstable features:

[features]
const = []

It can be written as follows:

#![cfg_attr(feature = "const", feature(const_fn, const_vec_new))]

#[const_fn(feature = "const")]
pub const fn empty_vec<T>() -> Vec<T> {
    Vec::new()
}

Code like this will be generated:

#![cfg_attr(feature = "const", feature(const_fn, const_vec_new))]

#[cfg(feature = "const")]
pub const fn empty_vec<T>() -> Vec<T> {
    Vec::new()
}

#[cfg(not(feature = "const"))]
pub fn empty_vec<T>() -> Vec<T> {
    Vec::new()
}

See test_suite for more examples.

Rust Version

The current minimum required Rust version is 1.30.

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.