https://github.com/tgrcdev/select_indices
Rust crate for splitting slices and Vecs into multiple mutable references via a list of indices
https://github.com/tgrcdev/select_indices
Last synced: 11 months ago
JSON representation
Rust crate for splitting slices and Vecs into multiple mutable references via a list of indices
- Host: GitHub
- URL: https://github.com/tgrcdev/select_indices
- Owner: TGRCdev
- License: mpl-2.0
- Created: 2021-11-12T23:25:37.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-08T19:32:40.000Z (over 3 years ago)
- Last Synced: 2025-02-28T09:48:30.610Z (12 months ago)
- Language: Rust
- Size: 95.7 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# select_indices

[](https://crates.io/crates/select_indices)
[](https://docs.rs/select_indices)

`select_indices` is a crate that provides iterators for seeking through a slice with a pre-made list of indices. It can simplify the readability of code and, in some cases, increase performance.
[Documentation](https://docs.rs/select_indices)
```rust
use select_indices::prelude::*;
fn main()
{
struct BankAccount {
pub name: String,
pub balance: f32,
}
let mut vec: Vec = vec![
BankAccount { name: "Joey Bag o' Donuts".to_string(), balance: 4.27 },
BankAccount { name: "Henry Howard Roosevelt".to_string(), balance: 83.20 },
BankAccount { name: "Jenny Jenson".to_string(), balance: 54.32 },
BankAccount { name: "The Dude".to_string(), balance: -134.01 },
// Assume there's like 300 of these
];
vec.select_indices_mut(&[1, 3]).for_each(|account| {
account.balance -= 20.00;
println!("{} now has ${}", account.name, account.balance);
});
}
```
There is also a `rayon` feature flag that provides ParallelIterator versions of `select_indices` iterators. In certain cases, these iterators can greatly improve performance over other methods of slice iteration.