#const-generics #const #macro-derive #macro #derive #no-std

no-std const_struct

macro that allows const structures to be passed as const generics

9 releases

0.4.7 Aug 28, 2024
0.4.6 Aug 28, 2024
0.3.1 Aug 13, 2024
0.2.1 Aug 12, 2024

#1183 in Rust patterns

MIT/Apache

37KB
979 lines

const_struct

This crate provides a way to create a struct with const generics and const values.

use const_struct::{primitive::F32Ty, F32};
pub fn tester<A: F32Ty>() {
    println!("a: {:?}", A::__DATA);
}
fn main() {
    tester::<F32!(0.5)>();
}

This crate is no_std. used unsafe code:

  • core::mem::zeroed
  • core::mem::transmute

See the Github README for more information.

Dependencies

~0.8–1.2MB
~24K SLoC