nslice/README.md

31 lines
810 B
Markdown
Raw Permalink Normal View History

2021-11-07 19:04:13 +00:00
# nslice
Structures for interpreting slices of variable length as arrays.
`nslice` provides `MinSlice` and `ExactSlice` for representing slices known to have
either exactly or at least some compile-time-known number of values.
This is useful when dealing with a slice whose length you expect to be exactly
or at least some particular length;
rather than making runtime checks on each access,
2024-04-01 02:42:47 +00:00
you can check the length once and access values freely with no copying.
2021-11-07 19:04:13 +00:00
```rust
# use nslice::MinSlice;
let slice = &[1, 2, 3, 4, 5, 6];
let minslice: &MinSlice<_, 3> = MinSlice::from_slice(slice).unwrap();
assert_eq!(minslice.tail.len(), 3);
assert_eq!(minslice.head[0], 1);
assert_eq!(minslice.tail[2], 6);
2024-04-01 02:42:47 +00:00
```
## MSRV
This project supports Rust 1.56.1 and onward.
2021-11-07 19:04:13 +00:00
## License
This project is licensed MIT.
2024-04-01 02:42:47 +00:00