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 reference conversions from ArrayOps #26

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
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
22 changes: 0 additions & 22 deletions src/sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,6 @@ macro_rules! impl_array_size {
impl<T> ArrayOps<T, $len> for Array<T, typenum::$ty> {
const SIZE: usize = $len;

#[inline]
fn as_core_array(&self) -> &[T; $len] {
&self.0
}

#[inline]
fn as_mut_core_array(&mut self) -> &mut [T; $len] {
&mut self.0
}

#[inline]
fn ref_from_core_array(array_ref: &[T; $len]) -> &Self {
// SAFETY: `Self` is a `repr(transparent)` newtype for `[T; $len]`
unsafe { &*array_ref.as_ptr().cast() }
}

#[inline]
fn ref_mut_from_core_array(array_ref: &mut [T; $len]) -> &mut Self {
// SAFETY: `Self` is a `repr(transparent)` newtype for `[T; $len]`
unsafe { &mut *array_ref.as_mut_ptr().cast() }
}

#[inline]
fn map_to_core_array<F, U>(self, f: F) -> [U; $len]
where
Expand Down
32 changes: 0 additions & 32 deletions src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,6 @@ pub trait ArrayOps<T, const N: usize>:
/// Not to be confused with [`AssociatedArraySize::Size`], which is [`typenum`]-based.
const SIZE: usize;

/// Returns a reference to the inner array.
fn as_core_array(&self) -> &[T; N];

/// Returns a mutable reference to the inner array.
fn as_mut_core_array(&mut self) -> &mut [T; N];

/// Create array reference from reference to Rust's core array type.
fn ref_from_core_array(arr: &[T; N]) -> &Self;

/// Create mutable array reference from reference to Rust's core array type.
fn ref_mut_from_core_array(arr: &mut [T; N]) -> &mut Self;

/// Returns an array of the same size as `self`, with function `f` applied to each element
/// in order.
fn map_to_core_array<F, U>(self, f: F) -> [U; N]
Expand All @@ -90,26 +78,6 @@ pub trait ArrayOps<T, const N: usize>:
impl<T, const N: usize> ArrayOps<T, N> for [T; N] {
const SIZE: usize = N;

#[inline]
fn as_core_array(&self) -> &[T; N] {
self
}

#[inline]
fn as_mut_core_array(&mut self) -> &mut [T; N] {
self
}

#[inline]
fn ref_from_core_array(array_ref: &[T; N]) -> &Self {
array_ref
}

#[inline]
fn ref_mut_from_core_array(array_ref: &mut [T; N]) -> &mut Self {
array_ref
}

#[inline]
fn map_to_core_array<F, U>(self, f: F) -> [U; N]
where
Expand Down
Loading