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

Add AsRef<[T]> and AsMut<[T]> trait implementations #1414

Closed
wants to merge 1 commit into from
Closed
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
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
Loading