const_struct
This crate provides a way to create a struct with const generics and const values.
use ;
This crate is no_std. used unsafe code:
core::mem::zeroedcore::mem::transmute
example code
use const_struct::{call_with_generics, const_struct, ConstStruct};
#[derive(ConstStruct, Debug)]
pub struct TestGenerics<const T: usize> {
float: f32,
}
const COUNT: usize = 7;
#[const_struct]
const B: TestGenerics<{ COUNT }> = TestGenerics { float: 0.0 };
const fn constant<const T: usize, S: TestGenericsTy<T>>() -> f32 {
S::FLOAT
}
const FLOAT: f32 = call_with_generics!(constant::<test_generics!(BTy)>());
If you see other complex example code, you see https://github.com/oligamiq/const_struct/tree/main/crates/test_code
See the Github README for more information.