stride

Crates.iostride
lib.rsstride
version0.4.0
created_at2021-01-18 21:25:26.14211+00
updated_at2025-06-06 16:14:01.827758+00
descriptionA strided slice type
homepage
repositoryhttps://github.com/rossmacarthur/vectrix
max_upload_size
id343679
size35,697
Ross MacArthur (rossmacarthur)

documentation

README

stride

Crates.io Version Docs.rs Latest Build Status

This crate 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, 6], 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 value S at compile time so that there is no runtime memory overhead to strided slices; Stride takes up the same amount of space as a slice.

Many slice-like operations are implemented for Stride including iteration and indexing. Method names are similar to those of the slice type.

Where you want a strided slice use:

  • ::new()``Stride::new to construct a &Stride<T, S>``Stride that wraps a &[T]``slice.
  • ::new_mut()``Stride::new_mut to construct a &mut Stride<T, S>``Stride that wraps a &mut [T]``slice.
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..3], &[7, 5]);

// .. or modify them.
stride[1] = 3;
assert_eq!(stride, &[1, 3, 5]);
assert_eq!(data, &[1, 2, 3, 4, 5, 6]);

License

This project is distributed under the terms of both the MIT license and the Apache License (Version 2.0).

See LICENSE-APACHE and LICENSE-MIT for details.

Commit count: 135

cargo fmt