Skip to content

Commit d0bb0b1

Browse files
committed
Add Ranked impls for the main array types
1 parent 3463417 commit d0bb0b1

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

src/layout/ranked.rs

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
//! array, whether known statically (via [`Dimensionality`]) or only at runtime. Blanket
66
//! implementations are provided for common pointer and container types.
77
8-
use crate::layout::dimensionality::{Dimensionality, D1};
8+
use crate::{
9+
layout::dimensionality::{Dimensionality, D1},
10+
ArrayBase,
11+
ArrayParts,
12+
ArrayRef,
13+
LayoutRef,
14+
RawData,
15+
RawRef,
16+
};
917

1018
/// A trait to unify type- and runtime-level number of dimensions.
1119
///
@@ -122,3 +130,60 @@ impl<T, const N: usize> Ranked for [T; N]
122130
1
123131
}
124132
}
133+
134+
impl<A, D, T: ?Sized> Ranked for ArrayParts<A, D, T>
135+
where D: Ranked
136+
{
137+
type Rank = D::Rank;
138+
139+
fn rank(&self) -> usize
140+
{
141+
self.dim.rank()
142+
}
143+
}
144+
145+
impl<S, D> Ranked for ArrayBase<S, D>
146+
where
147+
S: RawData,
148+
D: Ranked,
149+
{
150+
type Rank = D::Rank;
151+
152+
fn rank(&self) -> usize
153+
{
154+
self.parts.rank()
155+
}
156+
}
157+
158+
impl<A, D> Ranked for LayoutRef<A, D>
159+
where D: Ranked
160+
{
161+
type Rank = D::Rank;
162+
163+
fn rank(&self) -> usize
164+
{
165+
self.0.rank()
166+
}
167+
}
168+
169+
impl<A, D> Ranked for ArrayRef<A, D>
170+
where D: Ranked
171+
{
172+
type Rank = D::Rank;
173+
174+
fn rank(&self) -> usize
175+
{
176+
self.0.rank()
177+
}
178+
}
179+
180+
impl<A, D> Ranked for RawRef<A, D>
181+
where D: Ranked
182+
{
183+
type Rank = D::Rank;
184+
185+
fn rank(&self) -> usize
186+
{
187+
self.0.rank()
188+
}
189+
}

0 commit comments

Comments
 (0)