https://github.com/sigurd4/slice_ops
A selection of useful slice operations that run at compile-time
https://github.com/sigurd4/slice_ops
misc miscellaneous slice slice-manipulations slice-methods slice-operations slice-utilities slice-utility slices slices-utilities slices-utility useful util utility
Last synced: 3 months ago
JSON representation
A selection of useful slice operations that run at compile-time
- Host: GitHub
- URL: https://github.com/sigurd4/slice_ops
- Owner: sigurd4
- License: mit
- Created: 2023-12-29T00:25:24.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2025-02-17T18:13:16.000Z (8 months ago)
- Last Synced: 2025-04-30T20:07:12.995Z (5 months ago)
- Topics: misc, miscellaneous, slice, slice-manipulations, slice-methods, slice-operations, slice-utilities, slice-utility, slices, slices-utilities, slices-utility, useful, util, utility
- Language: Rust
- Homepage: https://crates.io/crates/slice_ops
- Size: 89.8 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/sigurd4/slice_ops/actions/workflows/build-nightly.yml)
[](https://github.com/sigurd4/slice_ops/actions/workflows/build-nightly-all-features.yml)[](https://github.com/sigurd4/slice_ops/actions/workflows/build-stable.yml)
[](https://github.com/sigurd4/slice_ops/actions/workflows/build-stable-all-features.yml)[](https://github.com/sigurd4/slice_ops/actions/workflows/test.yml)
[](https://github.com/sigurd4/slice_ops/actions/workflows/lint.yml)[](https://crates.io/crates/slice_ops)
[](https://opensource.org/licenses/MIT)
[](https://docs.rs/slice_ops)
[](https://app.codecov.io/github/sigurd4/slice_ops)# slice_ops
Provides many useful utility methods for slices.
This crate is a subset of the crate [`array__ops`](https://crates.io/crates/array__ops).
## integrate / differentiate
- `integrate`
- `differentiate````rust
use slice_ops::ops::*;let mut x = [1, 5, 5, 6, 2, -1, 0, 0, 0];
x.differentiate();
assert_eq!(x, [1, 4, 0, 1, -4, -3, 1, 0, 0]);
x.integrate();
assert_eq!(x, [1, 5, 5, 6, 2, -1, 0, 0, 0]);
```## find
- `find` / `rfind`
- `find_by` / `rfind_by`
- `find_by_key` / `rfind_by````rust
use slice_ops::ops::*;// v
let x = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3];let i = x.find(&5).unwrap();
assert_eq!(i, 4);
assert_eq!(x[i], 5);
```## argmax / argmin
- `argmax` / `argmin`
- `argmax_by` / `argmin_by`
- `argmax_by_key` / `argmin_by_key````rust
use slice_ops::ops::*;// v
let x = [1, 5, 5, 6, 2, -1, 0, -4, -1, 6];let i = x.argmax().unwrap();
assert_eq!(i, 3);
```## visit
- `visit` / `visit_mut`
- `rvisit` / `rvisit_mut`
- `visit_async` / `visit_mut_async`
- `try_visit` / `try_visit_mut`
- `try_rvisit` / `try_rvisit_mut`
- `try_visit_async` / `try_visit_mut_async````rust
use slice_ops::ops::*;let mut x = [0; 8];
let mut i = 0;
x.visit_mut(|e| {
i += 1;
*e = i;
});assert_eq!(x, [1, 2, 3, 4, 5, 6, 7, 8]);
```## ..._assign_all
- `add_assign_all` / `add_assign_all_async`
- `sub_assign_all` / `sub_assign_all_async`
- `mul_assign_all` / `mul_assign_all_async`
- `div_assign_all` / `div_assign_all_async`
- `rem_assign_all` / `rem_assign_all_async`
- `shl_assign_all` / `shl_assign_all_async`
- `shr_assign_all` / `shr_assign_all_async`
- `bitor_assign_all` / `bitor_assign_all_async`
- `bitand_assign_all` / `bitand_assign_all_async`
- `bitxor_assign_all` / `bitxor_assign_all_async`
- `neg_assign_all` / `neg_assign_all_async`
- `not_assign_all` / `not_assign_all_async````rust
use slice_ops::ops::*;let mut x = [1, 2, 3, 4, 5, 6, 7, 8];
x.mul_assign_all(2);
assert_eq!(x, [2, 4, 6, 8, 10, 12, 14, 16]);
```## shift
- `shift_many_left` / `shift_many_right`
- `shift_left` / `shift_right````rust
use slice_ops::ops::*;let mut register = [4, 5, 6, 7, 8, 9];
let mut io = [1, 2, 3];register.shift_many_right(&mut io);
assert_eq!(register, [1, 2, 3, 4, 5, 6]);
assert_eq!(io, [7, 8, 9]);
```## spread
- `spread` / `spread_mut`
```rust
#![feature(generic_const_exprs)]use slice_ops::ops::*;
let arr = [1, 2, 3];
let slice = arr.as_slice();let [odd, even] = slice.spread();
assert_eq!(odd, [1, 3]);
assert_eq!(even, [2]);
```## bit_rev_permutation
- `bit_rev_permutation`
- `digit_rev_permutation````rust
use slice_ops::ops::*;let mut arr = [0b000, 0b001, 0b010, 0b011, 0b100, 0b101, 0b110, 0b111];
arr.bit_rev_permutation();
assert_eq!(arr, [0b000, 0b100, 0b010, 0b110, 0b001, 0b101, 0b011, 0b111])
```## grey_code_permutation
- `grey_code_permutation`
```rust
use slice_ops::ops::*;let mut arr = [0b000, 0b001, 0b010, 0b011, 0b100, 0b101, 0b110, 0b111];
arr.as_mut_slice().grey_code_permutation();
assert_eq!(arr, [0b000, 0b001, 0b011, 0b010, 0b110, 0b111, 0b101, 0b100])
```## trim
- `trim` / `trim_mut`
- `trim_front` / `trim_front_mut`
- `trim_back` / `trim_back_mut````rust
use slice_ops::ops::*;let arr = [0, 0, 0, 1, 2, 3, 0, 0, 0];
let trimmed = arr.trim(|&e| e == 0);
assert_eq!(trimmed, &[1, 2, 3]);
```