From 234d61faa20e41de8327820a107cb38fcb45abef Mon Sep 17 00:00:00 2001 From: Andreas Longva Date: Mon, 14 Nov 2022 14:47:43 +0100 Subject: [PATCH] Rename SliceRange to DimRange --- src/base/matrix_view.rs | 51 ++++++++++++++++++++++++----------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/src/base/matrix_view.rs b/src/base/matrix_view.rs index 497a1553..ef024f19 100644 --- a/src/base/matrix_view.rs +++ b/src/base/matrix_view.rs @@ -651,7 +651,7 @@ macro_rules! matrix_view_impl ( /// /// Panics if the ranges overlap or if the first range is empty. #[inline] - pub fn $rows_range_pair, Range2: SliceRange>($me: $Me, r1: Range1, r2: Range2) + pub fn $rows_range_pair, Range2: DimRange>($me: $Me, r1: Range1, r2: Range2) -> ($MatrixView<'_, T, Range1::Size, C, S::RStride, S::CStride>, $MatrixView<'_, T, Range2::Size, C, S::RStride, S::CStride>) { @@ -687,7 +687,7 @@ macro_rules! matrix_view_impl ( /// /// Panics if the ranges overlap or if the first range is empty. #[inline] - pub fn $columns_range_pair, Range2: SliceRange>($me: $Me, r1: Range1, r2: Range2) + pub fn $columns_range_pair, Range2: DimRange>($me: $Me, r1: Range1, r2: Range2) -> ($MatrixView<'_, T, R, Range1::Size, S::RStride, S::CStride>, $MatrixView<'_, T, R, Range2::Size, S::RStride, S::CStride>) { @@ -816,7 +816,7 @@ impl> Matrix { /// * A left-open range `std::ops::RangeTo`, e.g., `.. 4` /// * A right-open range `std::ops::RangeFrom`, e.g., `4 ..` /// * A full range `std::ops::RangeFull`, e.g., `..` -pub trait SliceRange { +pub trait DimRange { /// Type of the range size. May be a type-level integer. type Size: Dim; @@ -829,7 +829,16 @@ pub trait SliceRange { fn size(&self, shape: D) -> Self::Size; } -impl SliceRange for usize { +/// A range with a size that may be known at compile-time. +/// +/// This is merely a legacy trait alias to minimize breakage. Use the [`DimRange`] trait instead. +#[deprecated = slice_deprecation_note!(DimRange)] +pub trait SliceRange: DimRange {} + +#[allow(deprecated)] +impl, D: Dim> SliceRange for R {} + +impl DimRange for usize { type Size = U1; #[inline(always)] @@ -848,7 +857,7 @@ impl SliceRange for usize { } } -impl SliceRange for Range { +impl DimRange for Range { type Size = Dynamic; #[inline(always)] @@ -867,7 +876,7 @@ impl SliceRange for Range { } } -impl SliceRange for RangeFrom { +impl DimRange for RangeFrom { type Size = Dynamic; #[inline(always)] @@ -886,7 +895,7 @@ impl SliceRange for RangeFrom { } } -impl SliceRange for RangeTo { +impl DimRange for RangeTo { type Size = Dynamic; #[inline(always)] @@ -905,7 +914,7 @@ impl SliceRange for RangeTo { } } -impl SliceRange for RangeFull { +impl DimRange for RangeFull { type Size = D; #[inline(always)] @@ -924,7 +933,7 @@ impl SliceRange for RangeFull { } } -impl SliceRange for RangeInclusive { +impl DimRange for RangeInclusive { type Size = Dynamic; #[inline(always)] @@ -957,8 +966,8 @@ impl> Matrix { cols: ColRange, ) -> MatrixView<'_, T, RowRange::Size, ColRange::Size, S::RStride, S::CStride> where - RowRange: SliceRange, - ColRange: SliceRange, + RowRange: DimRange, + ColRange: DimRange, { let (nrows, ncols) = self.shape_generic(); self.generic_view( @@ -977,8 +986,8 @@ impl> Matrix { cols: ColRange, ) -> MatrixView<'_, T, RowRange::Size, ColRange::Size, S::RStride, S::CStride> where - RowRange: SliceRange, - ColRange: SliceRange, + RowRange: DimRange, + ColRange: DimRange, { let (nrows, ncols) = self.shape_generic(); self.generic_view( @@ -990,7 +999,7 @@ impl> Matrix { /// View containing all the rows indexed by the range `rows`. #[inline] #[must_use] - pub fn rows_range>( + pub fn rows_range>( &self, rows: RowRange, ) -> MatrixView<'_, T, RowRange::Size, C, S::RStride, S::CStride> { @@ -1000,7 +1009,7 @@ impl> Matrix { /// View containing all the columns indexed by the range `rows`. #[inline] #[must_use] - pub fn columns_range>( + pub fn columns_range>( &self, cols: ColRange, ) -> MatrixView<'_, T, R, ColRange::Size, S::RStride, S::CStride> { @@ -1020,8 +1029,8 @@ impl> Matrix { cols: ColRange, ) -> MatrixViewMut<'_, T, RowRange::Size, ColRange::Size, S::RStride, S::CStride> where - RowRange: SliceRange, - ColRange: SliceRange, + RowRange: DimRange, + ColRange: DimRange, { self.view_range_mut(rows, cols) } @@ -1034,8 +1043,8 @@ impl> Matrix { cols: ColRange, ) -> MatrixViewMut<'_, T, RowRange::Size, ColRange::Size, S::RStride, S::CStride> where - RowRange: SliceRange, - ColRange: SliceRange, + RowRange: DimRange, + ColRange: DimRange, { let (nrows, ncols) = self.shape_generic(); self.generic_view_mut( @@ -1046,7 +1055,7 @@ impl> Matrix { /// Mutable view containing all the rows indexed by the range `rows`. #[inline] - pub fn rows_range_mut>( + pub fn rows_range_mut>( &mut self, rows: RowRange, ) -> MatrixViewMut<'_, T, RowRange::Size, C, S::RStride, S::CStride> { @@ -1055,7 +1064,7 @@ impl> Matrix { /// Mutable view containing all the columns indexed by the range `cols`. #[inline] - pub fn columns_range_mut>( + pub fn columns_range_mut>( &mut self, cols: ColRange, ) -> MatrixViewMut<'_, T, R, ColRange::Size, S::RStride, S::CStride> {