Crate stride[][src]

This library provides a slice like Stride<T, S> type where elements are spaced a constant S elements in memory.

For example, given an underlying slice &[1, 2, 3, 4, 5], the elements &[1, 3, 5] are a strided slice with a stride of 2. This crate makes use of const generics to provide the stride amount S at compile time so that there is no runtime memory overhead to strided slices.

Where you want a strided slice use:

Many slice like operations are implemented for Stride<T, N> including iteration and indexing.

Examples

use stride::Stride;

// The underlying data.
let data = &mut [1, 2, 7, 4, 5, 6];

// Create a strided slice with a stride of `2` referring to
// elements `1`, `7`, and `5`.
let stride = Stride::<_, 2>::new_mut(data);

assert_eq!(stride.len(), 3);

// We can use indexing to view values.
assert_eq!(stride[0], 1);
assert_eq!(stride[1], 7);
assert_eq!(stride[2], 5);

// .. and modify them.
stride[1] = 3;
assert_eq!(format!("{:?}", stride), "[1, 3, 5]");

Structs

Iter

Immutable stride iterator.

IterMut

Mutable stride iterator.

Stride

A constant strided slice.