Skip to content

Commit

Permalink
hybrid-array: change Deref::Target to [T] (#913)
Browse files Browse the repository at this point in the history
This makes porting existing `generic-array` code easier, and also means
deref coercion will allow `&Array<T, _>` to deref to `&[T]`, making it
usable anywhere a slice is.
  • Loading branch information
tarcieri authored May 31, 2023
1 parent 1c599fd commit 14b1e13
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions hybrid-array/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,21 @@ impl<T, U> Deref for Array<T, U>
where
U: ArraySize,
{
type Target = U::ArrayType<T>;
type Target = [T];

fn deref(&self) -> &U::ArrayType<T> {
&self.0
#[inline]
fn deref(&self) -> &[T] {
self.0.as_ref()
}
}

impl<T, U> DerefMut for Array<T, U>
where
U: ArraySize,
{
fn deref_mut(&mut self) -> &mut U::ArrayType<T> {
&mut self.0
#[inline]
fn deref_mut(&mut self) -> &mut [T] {
self.0.as_mut()
}
}

Expand Down Expand Up @@ -320,8 +322,6 @@ pub trait ArrayOps<T, const N: usize>:
+ AsMut<[T; N]>
+ Borrow<[T; N]>
+ BorrowMut<[T; N]>
+ Deref<Target = [T; N]>
+ DerefMut
+ From<[T; N]>
+ Index<usize>
+ Index<Range<usize>>
Expand Down

0 comments on commit 14b1e13

Please sign in to comment.