Merge pull request #480 from jturner314/as_ptr

Add as_ptr and as_mut_ptr methods
This commit is contained in:
Sébastien Crozet 2019-02-03 16:57:13 +01:00 committed by GitHub
commit 24e6ce6274
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 0 deletions

View File

@ -295,6 +295,15 @@ impl<N: Scalar, R: Dim, C: Dim, S: Storage<N, R, C>> Matrix<N, R, C, S> {
} }
} }
/// Returns a pointer to the start of the matrix.
///
/// If the matrix is not empty, this pointer is guaranteed to be aligned
/// and non-null.
#[inline]
pub fn as_ptr(&self) -> *const N {
self.data.ptr()
}
/// Tests whether `self` and `rhs` are equal up to a given epsilon. /// Tests whether `self` and `rhs` are equal up to a given epsilon.
/// ///
/// See `relative_eq` from the `RelativeEq` trait for more details. /// See `relative_eq` from the `RelativeEq` trait for more details.
@ -622,6 +631,15 @@ impl<N: Scalar, R: Dim, C: Dim, S: StorageMut<N, R, C>> Matrix<N, R, C, S> {
MatrixIterMut::new(&mut self.data) MatrixIterMut::new(&mut self.data)
} }
/// Returns a mutable pointer to the start of the matrix.
///
/// If the matrix is not empty, this pointer is guaranteed to be aligned
/// and non-null.
#[inline]
pub fn as_mut_ptr(&mut self) -> *mut N {
self.data.ptr_mut()
}
/// Mutably iterates through this matrix rows. /// Mutably iterates through this matrix rows.
/// ///
/// # Example /// # Example