Skip to content

Commit

Permalink
Add AsRef and AsMut trait implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsided committed Jun 21, 2024
1 parent d1edb4f commit d8fd966
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/base/array_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,20 @@ impl<T: Debug, const R: usize, const C: usize> Debug for ArrayStorage<T, R, C> {
}
}

impl<T, const R: usize, const C: usize> AsRef<[T]> for ArrayStorage<T, R, C> {
#[inline]
fn as_ref(&self) -> &[T] {
self.as_slice()
}
}

impl<T, const R: usize, const C: usize> AsMut<[T]> for ArrayStorage<T, R, C> {
#[inline]
fn as_mut(&mut self) -> &mut [T] {
self.as_mut_slice()
}
}

unsafe impl<T, const R: usize, const C: usize> RawStorage<T, Const<R>, Const<C>>
for ArrayStorage<T, R, C>
{
Expand Down
14 changes: 14 additions & 0 deletions src/base/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1351,6 +1351,20 @@ impl<T, R: Dim, C: Dim, S: RawStorageMut<T, R, C> + IsContiguous> Matrix<T, R, C
}
}

impl<T, R: Dim, C: Dim, S: RawStorage<T, R, C> + IsContiguous> Matrix<T, R, C, S> {
#[inline]
fn as_ref(&self) -> &[T] {
self.as_slice()
}
}

impl<T, R: Dim, C: Dim, S: RawStorageMut<T, R, C> + IsContiguous> Matrix<T, R, C, S> {
#[inline]
fn as_mut(&mut self) -> &mut [T] {
self.as_mut_slice()
}
}

impl<T: Scalar, D: Dim, S: RawStorageMut<T, D, D>> Matrix<T, D, D, S> {
/// Transposes the square matrix `self` in-place.
pub fn transpose_mut(&mut self) {
Expand Down
14 changes: 14 additions & 0 deletions src/base/vec_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,20 @@ impl<T, R: Dim, C: Dim> From<VecStorage<T, R, C>> for Vec<T> {
}
}

impl<T, R: Dim, C: Dim> AsRef<[T]> for VecStorage<T, R, C> {
#[inline]
fn as_ref(&self) -> &[T] {
self.as_slice()
}
}

impl<T, R: Dim, C: Dim> AsMut<[T]> for VecStorage<T, R, C> {
#[inline]
fn as_mut(&mut self) -> &mut [T] {
self.as_mut_slice()
}
}

/*
*
* Dyn − Static
Expand Down

0 comments on commit d8fd966

Please sign in to comment.