Skip to content

Commit 5202a50

Browse files
jturner314bluss
authored andcommitted
Expose CanSlice trait in public API
This makes it visible in the docs, but the private marker trick prevents other crates from implementing it.
1 parent 25a7bb0 commit 5202a50

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub use crate::dimension::IxDynImpl;
141141
pub use crate::dimension::NdIndex;
142142
pub use crate::error::{ErrorKind, ShapeError};
143143
pub use crate::indexes::{indices, indices_of};
144-
pub use crate::slice::{AxisSliceInfo, NewAxis, Slice, SliceArg, SliceInfo};
144+
pub use crate::slice::{AxisSliceInfo, CanSlice, NewAxis, Slice, SliceArg, SliceInfo};
145145

146146
use crate::iterators::Baseiter;
147147
use crate::iterators::{ElementsBase, ElementsBaseMut, Iter, IterMut, Lanes};

src/slice.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,16 @@ impl From<NewAxis> for AxisSliceInfo {
312312
/// consistent with the `&[AxisSliceInfo]` returned by `self.as_ref()` and that
313313
/// `self.as_ref()` always returns the same value when called multiple times.
314314
pub unsafe trait CanSlice<D: Dimension>: AsRef<[AxisSliceInfo]> {
315+
/// Dimensionality of the output array.
315316
type OutDim: Dimension;
316317

318+
/// Returns the number of axes in the input array.
317319
fn in_ndim(&self) -> usize;
318320

321+
/// Returns the number of axes in the output array.
319322
fn out_ndim(&self) -> usize;
323+
324+
private_decl! {}
320325
}
321326

322327
macro_rules! impl_canslice_samedim {
@@ -335,6 +340,8 @@ macro_rules! impl_canslice_samedim {
335340
fn out_ndim(&self) -> usize {
336341
self.out_ndim()
337342
}
343+
344+
private_impl! {}
338345
}
339346
};
340347
}
@@ -361,6 +368,8 @@ where
361368
fn out_ndim(&self) -> usize {
362369
self.out_ndim()
363370
}
371+
372+
private_impl! {}
364373
}
365374

366375
unsafe impl CanSlice<IxDyn> for [AxisSliceInfo] {
@@ -373,6 +382,8 @@ unsafe impl CanSlice<IxDyn> for [AxisSliceInfo] {
373382
fn out_ndim(&self) -> usize {
374383
self.iter().filter(|s| !s.is_index()).count()
375384
}
385+
386+
private_impl! {}
376387
}
377388

378389
/// Represents all of the necessary information to perform a slice.

0 commit comments

Comments
 (0)