const-if 0.1.3

This crate adds if-else expression into your constant functions
Documentation
  • Coverage
  • 25%
    1 out of 4 items documented0 out of 0 items with examples
  • Size
  • Source code size: 6.84 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.17 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • playXE/const-if
    2 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • playXE

const-if

This crate adds if-elif-else expression into your constant functions

Why

Since if expression not implemented in current implementation of const-fn I decided to create this macro

Example

    const fn min(x: i32, y: i32) -> i32 {
        const_if!(x < y => x;y)
    }
    const fn int_to_str(i: i32) -> &'static str {
        const_if!(
            i == 0 => "Zero";
            elif i == 1 => "One";
            elif i == 2 => "Two";
            elif i == 3 => "Three";
            elif i == 4 => "Four";
            elif i == 5 => "Five";
            elif i == 6 => "Six";
            elif i == 7 => "Seven";
            elif i == 8 => "Eight";
            elif i == 9 => "Nine";
            elif i == 10 => "Ten";
            else "Unknown"
        )
    }