Rust 1.50: const generics MVP is here

Posted by Radha Rani · 2021-02-10

Array IntoIterator and const generics are maturing. This snippet shows the new const generics allowing arrays of any size in traits. The future of Rust is compile-time everything. https://github.com/rust-lang/rust/releases/tag/1.50.0

// Rust 1.50 const generics MVP
struct ArrayWrapper<T, const N: usize> {
    data: [T; N],
}

impl<T: Default, const N: usize> ArrayWrapper<T, N> {
    fn new() -> Self {
        Self {
            data: std::array::from_fn(|_| T::default()),
        }
    }
}

Explore GitVibes