Skip to content

Commit

Permalink
hybrid-array: re-add AsRef<[T; N]>/AsMut<[T; N]> impls (#1031)
Browse files Browse the repository at this point in the history
These were removed in #1026 for more consistency with core arrays.

However, `generic-array` provides these impls, which makes removing them
problematic when migrating `generic-array`-based code, so it's easier to
keep them around, even if it breaks inference due to overlapping impls.
  • Loading branch information
tarcieri committed Dec 31, 2023
1 parent c37259c commit 37c1560
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions hybrid-array/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ where
}
}

impl<T, U, const N: usize> AsRef<[T; N]> for Array<T, U>
where
Self: ArrayOps<T, N>,
U: ArraySize,
{
#[inline]
fn as_ref(&self) -> &[T; N] {
self.as_core_array()
}
}

impl<T, U> AsMut<[T]> for Array<T, U>
where
U: ArraySize,
Expand All @@ -222,6 +233,17 @@ where
}
}

impl<T, U, const N: usize> AsMut<[T; N]> for Array<T, U>
where
Self: ArrayOps<T, N>,
U: ArraySize,
{
#[inline]
fn as_mut(&mut self) -> &mut [T; N] {
self.as_mut_core_array()
}
}

impl<T, U> Borrow<[T]> for Array<T, U>
where
U: ArraySize,
Expand Down

0 comments on commit 37c1560

Please sign in to comment.