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

no-std const_struct

macro that allows const structures to be passed as const generics

12 unstable releases (3 breaking)

0.5.3 Oct 7, 2024
0.5.1 Oct 7, 2024
0.4.8 Oct 6, 2024
0.4.7 Aug 28, 2024
0.2.1 Aug 12, 2024

#1091 in Rust patterns

Download history 225/week @ 2024-08-10 20/week @ 2024-08-17 798/week @ 2024-08-24 69/week @ 2024-08-31 3/week @ 2024-09-21 6/week @ 2024-09-28 490/week @ 2024-10-05 79/week @ 2024-10-12 4/week @ 2024-10-19 43/week @ 2024-11-02

149 downloads per month

MIT/Apache

38KB
1K SLoC

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.7–1.3MB
~24K SLoC