5 releases (3 breaking)

0.3.0 Nov 13, 2022
0.2.0 Dec 6, 2021
0.1.1 Feb 17, 2021
0.1.0 Feb 8, 2021
0.0.0 Jan 18, 2021

#2214 in Data structures

Download history 1/week @ 2024-11-13 5/week @ 2024-11-20 17/week @ 2024-11-27 31/week @ 2024-12-04 53/week @ 2024-12-11 14/week @ 2024-12-18 6/week @ 2024-12-25 4/week @ 2025-01-01 10/week @ 2025-01-08 27/week @ 2025-01-15 10/week @ 2025-01-22 8/week @ 2025-01-29 36/week @ 2025-02-05 32/week @ 2025-02-12 11/week @ 2025-02-19 43/week @ 2025-02-26

124 downloads per month
Used in 2 crates

MIT/Apache

27KB
443 lines

stride

Crates.io Version Docs.rs Latest Build Status

A strided slice type.

Getting started

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.

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]);

See the API documentation for more.

License

Licensed under either of

at your option.

No runtime deps