Skip to content

Commit aaa466e

Browse files
authored
Safe conversions between Array and [T; N] (#24)
Simply bounding on `ArrayType<T> = [T; N]` is enough to accomplish this. I've verified this change against a few of our repos (e.g. `block-ciphers`, `elliptic-curve`) and it does not seem to cause any inference problems. When this bound is in place there's no need for `ArrayOps<T, N>` either.
1 parent 0fff28d commit aaa466e

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/lib.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,20 +417,16 @@ where
417417

418418
impl<T, U, const N: usize> From<[T; N]> for Array<T, U>
419419
where
420-
Self: ArrayOps<T, N>,
421-
U: ArraySize,
420+
U: ArraySize<ArrayType<T> = [T; N]>,
422421
{
423422
#[inline]
424423
fn from(arr: [T; N]) -> Array<T, U> {
425-
// SAFETY: `Array` is a `repr(transparent)` newtype for `[T; N]` when it impls
426-
// `ArrayOps<T, N>`.
427-
unsafe { ptr::read(ManuallyDrop::new(arr).as_ptr().cast()) }
424+
Array(arr)
428425
}
429426
}
430427

431428
impl<T, U, const N: usize> From<Array<T, U>> for [T; N]
432429
where
433-
Array<T, U>: ArrayOps<T, N>,
434430
U: ArraySize<ArrayType<T> = [T; N]>,
435431
{
436432
#[inline]

0 commit comments

Comments
 (0)