const-if

Crates.ioconst-if
lib.rsconst-if
version0.1.3
sourcesrc
created_at2019-04-28 12:12:49.295303
updated_at2019-06-19 20:08:59.172191
descriptionThis crate adds if-else expression into your constant functions
homepage
repositoryhttps://github.com/playXE/const-if
max_upload_size
id130697
size7,214
playX (playXE)

documentation

README

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"
        )
    }

Commit count: 7

cargo fmt