Hacker News new | ask | show | jobs
by _dwt 2079 days ago
The future is here now, for the last ~week or so, on nightly Rust:

    #![feature(const_generics, const_evaluatable_checked)]

    fn append<T: Copy + Default, const N: usize, const M: usize>(
      xs: &[T; N], ys: &[T; M]) -> [T; N + M] {
        let mut result = [T::default(); N + M];
        result[..N].copy_from_slice(&xs[..]);
        result[N..].copy_from_slice(&ys[..]);
        result
    }

    fn main() {
        let arr = append(&[1i32; 3], &[2i32; 4]);
        dbg!(arr);
    }