Skip to content

Commit d5d6482

Browse files
jturner314bluss
authored andcommitted
Add DimAdd bounds to Dimension trait
This reduces how often an explicit `DimAdd` bound is necessary.
1 parent 319701d commit d5d6482

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/dimension/dimension_trait.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use alloc::vec::Vec;
1313

1414
use super::axes_of;
1515
use super::conversion::Convert;
16+
use super::ops::DimAdd;
1617
use super::{stride_offset, stride_offset_checked};
1718
use crate::itertools::{enumerate, zip};
1819
use crate::{Axis, DimMax};
@@ -51,6 +52,12 @@ pub trait Dimension:
5152
+ DimMax<IxDyn, Output=IxDyn>
5253
+ DimMax<<Self as Dimension>::Smaller, Output=Self>
5354
+ DimMax<<Self as Dimension>::Larger, Output=<Self as Dimension>::Larger>
55+
+ DimAdd<Self>
56+
+ DimAdd<<Self as Dimension>::Smaller>
57+
+ DimAdd<<Self as Dimension>::Larger>
58+
+ DimAdd<Ix0, Out = Self>
59+
+ DimAdd<Ix1, Out = <Self as Dimension>::Larger>
60+
+ DimAdd<IxDyn, Out = IxDyn>
5461
{
5562
/// For fixed-size dimension representations (e.g. `Ix2`), this should be
5663
/// `Some(ndim)`, and for variable-size dimension representations (e.g.

src/dimension/ops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::imp_prelude::*;
22

33
/// Adds the two dimensions at compile time.
4-
pub trait DimAdd<D: Dimension>: Dimension {
4+
pub trait DimAdd<D: Dimension> {
55
/// The sum of the two dimensions.
66
type Out: Dimension;
77
}

src/slice.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,14 +661,14 @@ pub trait SliceArg {
661661
/// Number of dimensions that this slicing argument produces in the output array.
662662
type OutDim: Dimension;
663663

664-
fn next_in_dim<D>(&self, _: PhantomData<D>) -> PhantomData<D::Out>
664+
fn next_in_dim<D>(&self, _: PhantomData<D>) -> PhantomData<<D as DimAdd<Self::InDim>>::Out>
665665
where
666666
D: Dimension + DimAdd<Self::InDim>,
667667
{
668668
PhantomData
669669
}
670670

671-
fn next_out_dim<D>(&self, _: PhantomData<D>) -> PhantomData<D::Out>
671+
fn next_out_dim<D>(&self, _: PhantomData<D>) -> PhantomData<<D as DimAdd<Self::OutDim>>::Out>
672672
where
673673
D: Dimension + DimAdd<Self::OutDim>,
674674
{

0 commit comments

Comments
 (0)