diff --git a/src/base/allocator.rs b/src/base/allocator.rs index 10c4bd315..8f175bf47 100644 --- a/src/base/allocator.rs +++ b/src/base/allocator.rs @@ -19,36 +19,36 @@ use std::mem::MaybeUninit; /// /// Every allocator must be both static and dynamic. Though not all implementations may share the /// same `Buffer` type. -pub trait Allocator: Any + Sized { +pub trait Allocator: Any + Sized { /// The type of buffer this allocator can instantiate. - type Buffer: StorageMut + IsContiguous + Clone + Debug; + type Buffer: StorageMut + IsContiguous + Clone + Debug; /// The type of buffer with uninitialized components this allocator can instantiate. - type BufferUninit: RawStorageMut, R, C> + IsContiguous; + type BufferUninit: RawStorageMut, R, C> + IsContiguous; /// Allocates a buffer with the given number of rows and columns without initializing its content. - fn allocate_uninit(nrows: R, ncols: C) -> Self::BufferUninit; + fn allocate_uninit(nrows: R, ncols: C) -> Self::BufferUninit; /// Assumes a data buffer to be initialized. /// /// # Safety /// The user must make sure that every single entry of the buffer has been initialized, /// or Undefined Behavior will immediately occur. - unsafe fn assume_init(uninit: Self::BufferUninit) -> Self::Buffer; + unsafe fn assume_init(uninit: Self::BufferUninit) -> Self::Buffer; /// Allocates a buffer initialized with the content of the given iterator. - fn allocate_from_iterator>( + fn allocate_from_iterator>( nrows: R, ncols: C, iter: I, - ) -> Self::Buffer; + ) -> Self::Buffer; #[inline] /// Allocates a buffer initialized with the content of the given row-major order iterator. - fn allocate_from_row_iterator>( + fn allocate_from_row_iterator>( nrows: R, ncols: C, iter: I, - ) -> Self::Buffer { + ) -> Self::Buffer { let mut res = Self::allocate_uninit(nrows, ncols); let mut count = 0; @@ -73,7 +73,7 @@ pub trait Allocator: Any + Sized { "Matrix init. from row iterator: iterator not long enough." ); - >::assume_init(res) + >::assume_init(res) } } } @@ -94,8 +94,8 @@ pub trait Reallocator: unsafe fn reallocate_copy( nrows: RTo, ncols: CTo, - buf: >::Buffer, - ) -> >::BufferUninit; + buf: >::Buffer, + ) -> >::BufferUninit; } /// The number of rows of the result of a componentwise operation on two matrices. diff --git a/src/base/array_storage.rs b/src/base/array_storage.rs index 4ac738a1e..5a5a8480a 100644 --- a/src/base/array_storage.rs +++ b/src/base/array_storage.rs @@ -113,7 +113,7 @@ unsafe impl RawStorage, Const> unsafe impl Storage, Const> for ArrayStorage where - DefaultAllocator: Allocator, Const, Buffer = Self>, + DefaultAllocator: Allocator, Const, Buffer = Self>, { #[inline] fn into_owned(self) -> Owned, Const> @@ -250,7 +250,7 @@ where V: SeqAccess<'a>, { let mut out: ArrayStorage, R, C> = - DefaultAllocator::allocate_uninit(Const::, Const::); + >::allocate_uninit(Const::, Const::); let mut curr = 0; while let Some(value) = visitor.next_element()? { diff --git a/src/base/default_allocator.rs b/src/base/default_allocator.rs index 3c1324139..a99f62fbd 100644 --- a/src/base/default_allocator.rs +++ b/src/base/default_allocator.rs @@ -34,21 +34,23 @@ use std::mem::MaybeUninit; pub struct DefaultAllocator; // Static - Static -impl Allocator, Const> +impl Allocator, Const> for DefaultAllocator { - type Buffer = ArrayStorage; - type BufferUninit = ArrayStorage, R, C>; + type Buffer = ArrayStorage; + type BufferUninit = ArrayStorage, R, C>; #[inline(always)] - fn allocate_uninit(_: Const, _: Const) -> ArrayStorage, R, C> { + fn allocate_uninit(_: Const, _: Const) -> ArrayStorage, R, C> { // SAFETY: An uninitialized `[MaybeUninit<_>; _]` is valid. let array: [[MaybeUninit; R]; C] = unsafe { MaybeUninit::uninit().assume_init() }; ArrayStorage(array) } #[inline(always)] - unsafe fn assume_init(uninit: ArrayStorage, R, C>) -> ArrayStorage { + unsafe fn assume_init( + uninit: ArrayStorage, R, C>, + ) -> ArrayStorage { // Safety: // * The caller guarantees that all elements of the array are initialized // * `MaybeUninit` and T are guaranteed to have the same layout @@ -58,12 +60,12 @@ impl Allocator, Const> } #[inline] - fn allocate_from_iterator>( + fn allocate_from_iterator>( nrows: Const, ncols: Const, iter: I, - ) -> Self::Buffer { - let mut res = Self::allocate_uninit(nrows, ncols); + ) -> Self::Buffer { + let mut res = >::allocate_uninit(nrows, ncols); let mut count = 0; // Safety: conversion to a slice is OK because the Buffer is known to be contiguous. @@ -87,12 +89,12 @@ impl Allocator, Const> // Dyn - Static // Dyn - Dyn #[cfg(any(feature = "std", feature = "alloc"))] -impl Allocator for DefaultAllocator { - type Buffer = VecStorage; - type BufferUninit = VecStorage, Dyn, C>; +impl Allocator for DefaultAllocator { + type Buffer = VecStorage; + type BufferUninit = VecStorage, Dyn, C>; #[inline] - fn allocate_uninit(nrows: Dyn, ncols: C) -> VecStorage, Dyn, C> { + fn allocate_uninit(nrows: Dyn, ncols: C) -> VecStorage, Dyn, C> { let mut data = Vec::new(); let length = nrows.value() * ncols.value(); data.reserve_exact(length); @@ -101,7 +103,9 @@ impl Allocator for DefaultAllocator { } #[inline] - unsafe fn assume_init(uninit: VecStorage, Dyn, C>) -> VecStorage { + unsafe fn assume_init( + uninit: VecStorage, Dyn, C>, + ) -> VecStorage { // Avoids a double-drop. let (nrows, ncols) = uninit.shape(); let vec: Vec<_> = uninit.into(); @@ -116,11 +120,11 @@ impl Allocator for DefaultAllocator { } #[inline] - fn allocate_from_iterator>( + fn allocate_from_iterator>( nrows: Dyn, ncols: C, iter: I, - ) -> Self::Buffer { + ) -> Self::Buffer { let it = iter.into_iter(); let res: Vec = it.collect(); assert!(res.len() == nrows.value() * ncols.value(), @@ -132,12 +136,12 @@ impl Allocator for DefaultAllocator { // Static - Dyn #[cfg(any(feature = "std", feature = "alloc"))] -impl Allocator for DefaultAllocator { - type Buffer = VecStorage; - type BufferUninit = VecStorage, R, Dyn>; +impl Allocator for DefaultAllocator { + type Buffer = VecStorage; + type BufferUninit = VecStorage, R, Dyn>; #[inline] - fn allocate_uninit(nrows: R, ncols: Dyn) -> VecStorage, R, Dyn> { + fn allocate_uninit(nrows: R, ncols: Dyn) -> VecStorage, R, Dyn> { let mut data = Vec::new(); let length = nrows.value() * ncols.value(); data.reserve_exact(length); @@ -147,7 +151,9 @@ impl Allocator for DefaultAllocator { } #[inline] - unsafe fn assume_init(uninit: VecStorage, R, Dyn>) -> VecStorage { + unsafe fn assume_init( + uninit: VecStorage, R, Dyn>, + ) -> VecStorage { // Avoids a double-drop. let (nrows, ncols) = uninit.shape(); let vec: Vec<_> = uninit.into(); @@ -162,11 +168,11 @@ impl Allocator for DefaultAllocator { } #[inline] - fn allocate_from_iterator>( + fn allocate_from_iterator>( nrows: R, ncols: Dyn, iter: I, - ) -> Self::Buffer { + ) -> Self::Buffer { let it = iter.into_iter(); let res: Vec = it.collect(); assert!(res.len() == nrows.value() * ncols.value(), @@ -193,7 +199,7 @@ where unsafe fn reallocate_copy( rto: Const, cto: Const, - buf: >::Buffer, + buf: >::Buffer, ) -> ArrayStorage, RTO, CTO> { let mut res = , Const>>::allocate_uninit(rto, cto); diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 7daa4f1a0..5750a8fc4 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -383,7 +383,7 @@ impl RowDVector { } } -impl UninitMatrix +impl UninitMatrix where DefaultAllocator: Allocator, { @@ -533,7 +533,7 @@ impl> Matrix { max_relative: T::Epsilon, ) -> bool where - T: RelativeEq, + T: RelativeEq + Scalar, R2: Dim, C2: Dim, SB: Storage, diff --git a/src/base/ops.rs b/src/base/ops.rs index d5cf3a519..15d2fe267 100644 --- a/src/base/ops.rs +++ b/src/base/ops.rs @@ -633,7 +633,7 @@ where SB: Storage, SA: StorageMut + IsContiguous + Clone, // TODO: get rid of the IsContiguous ShapeConstraint: AreMultipliable, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator = SA>, { #[inline] fn mul_assign(&mut self, rhs: Matrix) { @@ -651,7 +651,7 @@ where SA: StorageMut + IsContiguous + Clone, // TODO: get rid of the IsContiguous ShapeConstraint: AreMultipliable, // TODO: this is too restrictive. See comments for the non-ref version. - DefaultAllocator: Allocator, + DefaultAllocator: Allocator = SA>, { #[inline] fn mul_assign(&mut self, rhs: &'b Matrix) { diff --git a/src/base/storage.rs b/src/base/storage.rs index 168253e65..0564ac0f4 100644 --- a/src/base/storage.rs +++ b/src/base/storage.rs @@ -12,22 +12,22 @@ use crate::base::Scalar; */ /// The data storage for the sum of two matrices with dimensions `(R1, C1)` and `(R2, C2)`. pub type SameShapeStorage = - , SameShapeC>>::Buffer; + , SameShapeC>>::Buffer; // TODO: better name than Owned ? /// The owned data storage that can be allocated from `S`. -pub type Owned = >::Buffer; +pub type Owned = >::Buffer; /// The owned data storage that can be allocated from `S`. -pub type OwnedUninit = >::BufferUninit; +pub type OwnedUninit = >::BufferUninit; /// The row-stride of the owned data storage for a buffer of dimension `(R, C)`. pub type RStride = - <>::Buffer as RawStorage>::RStride; + <>::Buffer as RawStorage>::RStride; /// The column-stride of the owned data storage for a buffer of dimension `(R, C)`. pub type CStride = - <>::Buffer as RawStorage>::CStride; + <>::Buffer as RawStorage>::CStride; /// The trait shared by all matrix data storage. /// @@ -139,7 +139,7 @@ pub unsafe trait RawStorage: Sized { /// should **not** allow the user to modify the size of the underlying buffer with safe methods /// (for example the `VecStorage::data_mut` method is unsafe because the user could change the /// vector's size so that it no longer contains enough elements: this will lead to UB. -pub unsafe trait Storage: RawStorage { +pub unsafe trait Storage: RawStorage { /// Builds a matrix data storage that does not contain any reference. fn into_owned(self) -> Owned where @@ -260,12 +260,12 @@ pub unsafe trait RawStorageMut: RawStorage { /// # Safety /// /// See safety note for `Storage`, `RawStorageMut`. -pub unsafe trait StorageMut: +pub unsafe trait StorageMut: Storage + RawStorageMut { } -unsafe impl StorageMut for S +unsafe impl StorageMut for S where R: Dim, C: Dim, diff --git a/src/base/vec_storage.rs b/src/base/vec_storage.rs index 5b29b6a30..000c4fcfc 100644 --- a/src/base/vec_storage.rs +++ b/src/base/vec_storage.rs @@ -264,7 +264,7 @@ unsafe impl RawStorage for VecStorage { unsafe impl Storage for VecStorage where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator = Self>, { #[inline] fn into_owned(self) -> Owned @@ -315,7 +315,7 @@ unsafe impl RawStorage for VecStorage { unsafe impl Storage for VecStorage where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator = Self>, { #[inline] fn into_owned(self) -> Owned diff --git a/src/geometry/point.rs b/src/geometry/point.rs index 94bd95a75..9072f7210 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -107,7 +107,7 @@ where impl Serialize for OPoint where DefaultAllocator: Allocator, - >::Buffer: Serialize, + >::Buffer: Serialize, { fn serialize(&self, serializer: S) -> Result where @@ -121,7 +121,7 @@ where impl<'a, T: Scalar, D: DimName> Deserialize<'a> for OPoint where DefaultAllocator: Allocator, - >::Buffer: Deserialize<'a>, + >::Buffer: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result where @@ -304,7 +304,7 @@ where #[inline] pub fn iter( &self, - ) -> MatrixIter<'_, T, D, Const<1>, >::Buffer> { + ) -> MatrixIter<'_, T, D, Const<1>, >::Buffer> { self.coords.iter() } @@ -335,7 +335,7 @@ where #[inline] pub fn iter_mut( &mut self, - ) -> MatrixIterMut<'_, T, D, Const<1>, >::Buffer> { + ) -> MatrixIterMut<'_, T, D, Const<1>, >::Buffer> { self.coords.iter_mut() } diff --git a/src/geometry/point_construction.rs b/src/geometry/point_construction.rs index b60e65ac1..c4785466c 100644 --- a/src/geometry/point_construction.rs +++ b/src/geometry/point_construction.rs @@ -174,7 +174,7 @@ where #[cfg(feature = "arbitrary")] impl Arbitrary for OPoint where - >::Buffer: Send, + >::Buffer: Send, DefaultAllocator: Allocator, { #[inline] diff --git a/src/geometry/point_conversion.rs b/src/geometry/point_conversion.rs index 81870379e..93060aff3 100644 --- a/src/geometry/point_conversion.rs +++ b/src/geometry/point_conversion.rs @@ -115,7 +115,7 @@ impl From<[Point::Element; 2]>, T::Element: Scalar + Copy, - >>::Buffer: Copy, + >>::Buffer: Copy, { #[inline] fn from(arr: [Point; 2]) -> Self { @@ -128,7 +128,7 @@ impl From<[Point::Element; 4]>, T::Element: Scalar + Copy, - >>::Buffer: Copy, + >>::Buffer: Copy, { #[inline] fn from(arr: [Point; 4]) -> Self { @@ -146,7 +146,7 @@ impl From<[Point::Element; 8]>, T::Element: Scalar + Copy, - >>::Buffer: Copy, + >>::Buffer: Copy, { #[inline] fn from(arr: [Point; 8]) -> Self { @@ -168,7 +168,7 @@ impl From<[Point::Element; 16]>, T::Element: Scalar + Copy, - >>::Buffer: Copy, + >>::Buffer: Copy, { #[inline] fn from(arr: [Point; 16]) -> Self { diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index d09a862a5..2bbe8dbc6 100644 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -77,7 +77,7 @@ impl fmt::Debug for Rotation { impl hash::Hash for Rotation where - , Const>>::Buffer: hash::Hash, + , Const>>::Buffer: hash::Hash, { fn hash(&self, state: &mut H) { self.matrix.hash(state)