Skip to content

Commit

Permalink
hybrid-array: unconditional ArrayOps/AssociatedArraySize impls (#…
Browse files Browse the repository at this point in the history
…1013)

Makes these traits always impl'd for `[T; N]` and `Array<T, U>`
respectively.
  • Loading branch information
tarcieri authored Dec 31, 2023
1 parent 78e7bf7 commit fdb7527
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
4 changes: 0 additions & 4 deletions hybrid-array/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ macro_rules! impl_array_size {
impl<T> AssociatedArraySize for [T; $len] {
type Size = typenum::$ty;
}

impl<T> AssociatedArraySize for Array<T, typenum::$ty> {
type Size = typenum::$ty;
}
)+
};
}
Expand Down
15 changes: 9 additions & 6 deletions hybrid-array/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,7 @@ fn check_slice_length<T, U: ArraySize>(slice: &[T]) -> Result<(), TryFromSliceEr

/// Array operations which are const generic over a given array size.
pub trait ArrayOps<T, const N: usize>:
AssociatedArraySize
+ Borrow<[T; N]>
Borrow<[T; N]>
+ BorrowMut<[T; N]>
+ From<[T; N]>
+ FromFn<T>
Expand Down Expand Up @@ -609,10 +608,7 @@ pub trait ArrayOps<T, const N: usize>:
F: FnMut(T) -> U;
}

impl<T, const N: usize> ArrayOps<T, N> for [T; N]
where
Self: AssociatedArraySize,
{
impl<T, const N: usize> ArrayOps<T, N> for [T; N] {
const SIZE: usize = N;

#[inline]
Expand Down Expand Up @@ -703,6 +699,13 @@ pub trait AssociatedArraySize: Sized {
type Size: ArraySize;
}

impl<T, U> AssociatedArraySize for Array<T, U>
where
U: ArraySize,
{
type Size = U;
}

/// Construct an array type from the given function.
pub trait FromFn<T>: Sized {
/// Create array using the given callback function for each element.
Expand Down

0 comments on commit fdb7527

Please sign in to comment.