constify

Crates.ioconstify
lib.rsconstify
version0.0.1
created_at2026-01-20 23:34:47.459964+00
updated_at2026-01-20 23:34:47.459964+00
descriptionA procedural macro for basic static specialization.
homepagehttps://github.com/DGriffin91/egui_software_backend
repositoryhttps://github.com/DGriffin91/egui_software_backend
max_upload_size
id2057848
size11,550
Griffin (DGriffin91)

documentation

README

constify

Example usage:

#[constify]
fn foo(
    #[constify] a: bool, 
    #[constify] b: bool, 
    c: bool
) -> u32 {
    let mut sum = 0;
    if a {
        sum += 1;
    }
    if b {
        sum += 10;
    }
    if c {
        sum += 100;
    }
    sum
}

Expansion:

#[inline(always)]
fn foo(a: bool, b: bool, c: bool) -> u32 {
    fn foo<const a: bool, const b: bool>(c: bool) -> u32 {
        let mut sum = 0;
        if a {
            sum += 1;
        }
        if b {
            sum += 10;
        }
        if c {
            sum += 100;
        }
        sum
    }
    match (a, b) {
        (false, false) => foo::<false, false>(c),
        (true, false) => foo::<true, false>(c),
        (false, true) => foo::<false, true>(c),
        (true, true) => foo::<true, true>(c),
    }
}

Inspired by https://github.com/TennyZhuang/const-currying-rs

Commit count: 142

cargo fmt