Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ where
/// Panics if `U` is 0.
#[allow(clippy::arithmetic_side_effects)]
#[inline]
pub fn slice_as_chunks(buf: &[T]) -> (&[Self], &[T]) {
assert_ne!(U::USIZE, 0, "chunk size must be non-zero");
pub const fn slice_as_chunks(buf: &[T]) -> (&[Self], &[T]) {
assert!(U::USIZE != 0, "chunk size must be non-zero");
// Arithmetic safety: we have checked that `N::USIZE` is not zero, thus
// division always returns correct result. `tail_pos` can not be bigger than `buf.len()`,
// thus overflow on multiplication and underflow on substraction are impossible.
Expand All @@ -315,8 +315,8 @@ where
/// Panics if `U` is 0.
#[allow(clippy::arithmetic_side_effects)]
#[inline]
pub fn slice_as_chunks_mut(buf: &mut [T]) -> (&mut [Self], &mut [T]) {
assert_ne!(U::USIZE, 0, "chunk size must be non-zero");
pub const fn slice_as_chunks_mut(buf: &mut [T]) -> (&mut [Self], &mut [T]) {
assert!(U::USIZE != 0, "chunk size must be non-zero");
// Arithmetic safety: we have checked that `N::USIZE` is not zero, thus
// division always returns correct result. `tail_pos` can not be bigger than `buf.len()`,
// thus overflow on multiplication and underflow on substraction are impossible.
Expand Down Expand Up @@ -375,28 +375,28 @@ where
{
/// Transform slice to slice of core array type.
#[inline]
pub fn cast_slice_to_core(slice: &[Self]) -> &[[T; N]] {
pub const fn cast_slice_to_core(slice: &[Self]) -> &[[T; N]] {
// SAFETY: `Self` is a `repr(transparent)` newtype for `[T; N]`
unsafe { slice::from_raw_parts(slice.as_ptr().cast(), slice.len()) }
}

/// Transform mutable slice to mutable slice of core array type.
#[inline]
pub fn cast_slice_to_core_mut(slice: &mut [Self]) -> &mut [[T; N]] {
pub const fn cast_slice_to_core_mut(slice: &mut [Self]) -> &mut [[T; N]] {
// SAFETY: `Self` is a `repr(transparent)` newtype for `[T; N]`
unsafe { slice::from_raw_parts_mut(slice.as_mut_ptr().cast(), slice.len()) }
}

/// Transform slice to slice of core array type.
#[inline]
pub fn cast_slice_from_core(slice: &[[T; N]]) -> &[Self] {
pub const fn cast_slice_from_core(slice: &[[T; N]]) -> &[Self] {
// SAFETY: `Self` is a `repr(transparent)` newtype for `[T; N]`
unsafe { slice::from_raw_parts(slice.as_ptr().cast(), slice.len()) }
}

/// Transform mutable slice to mutable slice of core array type.
#[inline]
pub fn cast_slice_from_core_mut(slice: &mut [[T; N]]) -> &mut [Self] {
pub const fn cast_slice_from_core_mut(slice: &mut [[T; N]]) -> &mut [Self] {
// SAFETY: `Self` is a `repr(transparent)` newtype for `[T; N]`
unsafe { slice::from_raw_parts_mut(slice.as_mut_ptr().cast(), slice.len()) }
}
Expand Down