Skip to content

Commit

Permalink
DOC: Add comment on Axis about why we don't have conversion traits
Browse files Browse the repository at this point in the history
  • Loading branch information
bluss committed Mar 27, 2021
1 parent be13f3d commit 7be7fd5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/dimension/axis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,21 @@

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

Expand Down

0 comments on commit 7be7fd5

Please sign in to comment.