Skip to content

Commit

Permalink
hybrid-array: add Borrow(Mut) bounds to SliceOps (#1022)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri authored Dec 31, 2023
1 parent 8c3dd87 commit e8ed114
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 @@ -250,6 +250,16 @@ where
}
}

impl<T, U> Borrow<[T]> for Array<T, U>
where
U: ArraySize,
{
#[inline]
fn borrow(&self) -> &[T] {
self.0.as_ref()
}
}

impl<T, U, const N: usize> Borrow<[T; N]> for Array<T, U>
where
Self: ArrayOps<T, N>,
Expand All @@ -261,6 +271,16 @@ where
}
}

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

impl<T, U, const N: usize> BorrowMut<[T; N]> for Array<T, U>
where
Self: ArrayOps<T, N>,
Expand Down Expand Up @@ -633,6 +653,8 @@ impl<T, const N: usize> ArrayOps<T, N> for [T; N] {
pub trait SliceOps<T>:
AsRef<[T]>
+ AsMut<[T]>
+ Borrow<[T]>
+ BorrowMut<[T]>
+ Index<usize>
+ Index<Range<usize>>
+ IndexMut<usize>
Expand Down

0 comments on commit e8ed114

Please sign in to comment.