Skip to content

Lars-Schumann/cement

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What?

Turn your Vec's (or other compatible collections) into Arrays or Slices at compile time!

Why?

const_make_global isn't real, it can't hurt me. (Also it can't give you [T; N] Arrays, only &[T] Slices)

How?

#![feature(const_heap)]
#![feature(const_trait_impl)]
#![feature(maybe_uninit_array_assume_init)]

use cement::cement;

fn main() {
    #[expect(clippy::vec_init_then_push)]
    const fn one_two_three() -> Vec<i32> {
        let mut vec: Vec<i32> = Vec::new();
        vec.push(1);
        vec.push(2);
        vec.push(3);
        vec
    }

    cement!(pub const ARRAY1: [i32; ?] = one_two_three());
    cement!(static ARRAY2: [i32; ?] = one_two_three());

    cement!(pub(in self) const ARRAY3: [i32; 3] = one_two_three());
    cement!(pub static ARRAY4: [i32; 3] = one_two_three());

    cement!(static ARRAY5: &[i32] = one_two_three());

    dbg!(ARRAY1, ARRAY2, ARRAY3, ARRAY4, ARRAY5);
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors