Crate const_ft[][src]

A macro for easy generation and wrapping of a const function under a const_fn feature gate.

The macro will generate two functions with the same name - one const fn for when the feature gate const_fn is enabled and the other for the all other cases.

const fns are unstable, and the const_fn feature gate should be enabled only on nightly.

The macro accepts a single function block, as an input. To include multiple functions, you have to use separate macro calls. The macro works for public, private and pub(x) functions.

To install this crate as a dependency, add it to your Cargo.toml:

const_ft = { version =  "0.1", features = "const_fn" }


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

extern crate const_ft;

const_ft! {
     pub fn some_function() -> u32 {

fn main() {
    assert_eq!(some_function(), 1u32);