@@ -2,7 +2,25 @@ use core::iter::Map;
22
33use crate :: layout:: ranked:: Ranked ;
44
5- /// A trait for array shapes.
5+ /// A trait for array shapes: lists of `usize` describing the length of each dimension of an array.
6+ ///
7+ /// ## Size Limits
8+ /// Arrays cannot have more than [`usize::MAX`] elements; otherwise, it would not be possible
9+ /// to address all of the elements in-memory. In addition, since an array may have negative strides
10+ /// (i.e., elements _behind_ the current pointer in memory), arrays must be addressable using
11+ /// [`isize`]. So no array can have more than [`isize::MAX`] elements. Finally, for multi-byte
12+ /// element types, the total byte size of the array also cannot exceed `isize::MAX`.
13+ ///
14+ /// Implementing `Shape` for a type does not guarantee that the type will always represent an
15+ /// array that adheres to these size limits. It does, however, provide access to two methods that
16+ /// can cheaply check these invariants: [`Shape::size_checked`] and [`Shape::size_bytes_checked`].
17+ /// In order for an instance of a `Shape` to be valid, both of these methods must return `Some(_)`.
18+ ///
19+ /// ## Mutability
20+ /// The `Shape` trait does not provide any sort of mutability for the lengths of each axis.
21+ /// This allows users to define constant-sized shapes, which can significantly increase performance.
22+ ///
23+ /// Since `Shape` is still experimental, the mechanisms for mutability are still being designed.
624pub trait Shape : Ranked
725{
826 /// The iterator type over the dimensions of the shape.
@@ -27,7 +45,6 @@ pub trait Shape: Ranked
2745
2846 /// Get the number of bytes that this array would fill.
2947 ///
30- /// # Safety
3148 /// This method checks for bytes overflow past `isize`. If this method returns `Some(_)`,
3249 /// then users know that an allocated array is indexable using `isize` offsets.
3350 fn size_bytes_checked < T > ( & self ) -> Option < usize >
0 commit comments