Skip to content

Commit 7be7fd5

Browse files
committed
DOC: Add comment on Axis about why we don't have conversion traits
1 parent be13f3d commit 7be7fd5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/dimension/axis.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,21 @@
88

99
/// An axis index.
1010
///
11-
/// An axis one of an array’s “dimensions”; an *n*-dimensional array has *n* axes.
12-
/// Axis *0* is the array’s outermost axis and *n*-1 is the innermost.
11+
/// An axis one of an array’s “dimensions”; an *n*-dimensional array has *n*
12+
/// axes. Axis *0* is the array’s outermost axis and *n*-1 is the innermost.
1313
///
1414
/// All array axis arguments use this type to make the code easier to write
1515
/// correctly and easier to understand.
16+
///
17+
/// For example: in a method like `index_axis(axis, index)` the code becomes
18+
/// self-explanatory when it's called like `.index_axis(Axis(1), i)`; it's
19+
/// evident which integer is the axis number and which is the index.
20+
///
21+
/// Note: This type does **not** implement From/Into usize and similar trait
22+
/// based conversions, because we want to preserve code readability and quality.
23+
///
24+
/// `Axis(1)` in itself is a very clear code style and the style that should be
25+
/// avoided is code like `1.into()`.
1626
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
1727
pub struct Axis(pub usize);
1828

0 commit comments

Comments
 (0)