core::index
Indexing + slicing traits.
arr[i], arr[i,j], arr[1:3] all desugar through these
traits. xs[i] / xs[i] = v on a struct or enum call index /
index_set; fixed arrays and GcBuf<T> index directly (no call).
a[i:j:k] calls a.slice(i..j) (then .step(k)), see
collections::slice. Slices follow Python: bounds clamp to the
length (never panic), a negative step reads them from the end.
Structs
SliceArgSource
pub struct SliceArga:b:k as an axis argument of a multi-axis index: a[1:, ::2] is
a[(SliceArg::new(1, none, none), SliceArg::new(none, none, 2))].
A part left out is none. indices applies the rules of a 1-D
slice: negative bounds count from the end, bounds clamp, a negative
step walks backwards, a zero step panics.
:, the whole axis.start:stop:step; a part left out isnone.(first, count, step): the positionsfirst,first + step, .. (countof them) this slice picks from an axis of lengthlen.
RestSource
pub struct Rest.. among other axis arguments (a[.., 0]): every axis the others
leave, taken whole. At most one per index.
NewAxisSource
pub struct NewAxisnone as an axis argument (a[:, none]): a new axis of length 1.
Traits
IndexSource
pub trait Index<I>a[i] and a[i, j] as a read: index(i).
self[idx].
IndexSetSource
pub trait IndexSet<I, V>a[i] = v: index_set(i, v). V is a parameter, so one index
may take several kinds of value (a[:, 0] = 0.0 stores a scalar,
a[:, 0] = col a column); the value's type picks the impl.
self[idx] = value.
SliceableSource
pub trait Sliceable<R>a[i:j] (not Slice: that is the view type, and one glob-imported
name cannot be both).
self[range].
AxisIndexedSource
pub trait AxisIndexedA type indexed by axes. In x[..] on such a type every integer part
is an isize position (other integer types convert, a literal is
one), none is NewAxis and .. beside other parts is Rest, so
one set of Index / IndexSet impls over isize serves every call.