Crate const_fn[−][src]
An attribute for easy generation of const functions with conditional compilations.
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)
Attribute Macros
const_fn | An attribute for easy generation of const functions with conditional compilations. |