Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove uses of ArrayOps bounds #25

Merged
merged 1 commit into from
Jan 25, 2024
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
52 changes: 22 additions & 30 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,22 @@ where

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

impl<T, U, const N: usize> AsRef<Array<T, U>> for [T; N]
where
Array<T, U>: ArrayOps<T, N>,
U: ArraySize,
U: ArraySize<ArrayType<T> = [T; N]>,
{
#[inline]
fn as_ref(&self) -> &Array<T, U> {
Array::ref_from_core_array(self)
// SAFETY: `Self` is a `repr(transparent)` newtype for `[T; $len]`
unsafe { &*self.as_ptr().cast() }
}
}

Expand All @@ -284,23 +283,22 @@ where

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

impl<T, U, const N: usize> AsMut<Array<T, U>> for [T; N]
where
Array<T, U>: ArrayOps<T, N>,
U: ArraySize,
U: ArraySize<ArrayType<T> = [T; N]>,
{
#[inline]
fn as_mut(&mut self) -> &mut Array<T, U> {
Array::ref_mut_from_core_array(self)
// SAFETY: `Self` is a `repr(transparent)` newtype for `[T; $len]`
unsafe { &mut *self.as_mut_ptr().cast() }
}
}

Expand All @@ -316,12 +314,11 @@ where

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

Expand All @@ -337,12 +334,11 @@ where

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

Expand Down Expand Up @@ -437,45 +433,41 @@ where

impl<'a, T, U, const N: usize> From<&'a [T; N]> for &'a Array<T, U>
where
Array<T, U>: ArrayOps<T, N>,
U: ArraySize,
U: ArraySize<ArrayType<T> = [T; N]>,
{
#[inline]
fn from(array_ref: &'a [T; N]) -> &'a Array<T, U> {
<Array<T, U>>::ref_from_core_array(array_ref)
array_ref.as_ref()
}
}

impl<'a, T, U, const N: usize> From<&'a Array<T, U>> for &'a [T; N]
where
Array<T, U>: ArrayOps<T, N>,
U: ArraySize,
U: ArraySize<ArrayType<T> = [T; N]>,
{
#[inline]
fn from(array_ref: &'a Array<T, U>) -> &'a [T; N] {
array_ref.as_core_array()
array_ref.as_ref()
}
}

impl<'a, T, U, const N: usize> From<&'a mut [T; N]> for &'a mut Array<T, U>
where
Array<T, U>: ArrayOps<T, N>,
U: ArraySize,
U: ArraySize<ArrayType<T> = [T; N]>,
{
#[inline]
fn from(array_ref: &'a mut [T; N]) -> &'a mut Array<T, U> {
<Array<T, U>>::ref_mut_from_core_array(array_ref)
array_ref.as_mut()
}
}

impl<'a, T, U, const N: usize> From<&'a mut Array<T, U>> for &'a mut [T; N]
where
Array<T, U>: ArrayOps<T, N>,
U: ArraySize,
U: ArraySize<ArrayType<T> = [T; N]>,
{
#[inline]
fn from(array_ref: &'a mut Array<T, U>) -> &'a mut [T; N] {
array_ref.as_mut_core_array()
array_ref.as_mut()
}
}

Expand Down
Loading