const-util 2.3.0

Stable implementations for some missing const functions
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#[rustversion::since(1.87)]
#[expect(clippy::incompatible_msrv)]
pub(crate) const fn copy_from_slice<T: Copy>(src: &[T], dst: &mut [T]) {
    dst.copy_from_slice(src);
}

#[rustversion::before(1.87)]
pub(crate) const fn copy_from_slice<T: Copy>(src: &[T], dst: &mut [T]) {
    assert!(src.len() == dst.len());
    // SAFETY: T: Copy. This is literally how copy_from_slice is implemented.
    unsafe {
        core::ptr::copy_nonoverlapping(src.as_ptr(), dst.as_mut_ptr(), src.len());
    }
}