select_indices

Crates.ioselect_indices
lib.rsselect_indices
version3.0.0
sourcesrc
created_at2021-11-13 12:14:59.383372
updated_at2022-03-21 22:06:52.738532
descriptionIterators for taking multiple shared/exclusive references from a slice
homepage
repositoryhttps://github.com/TGRCdev/select_indices
max_upload_size
id481363
size82,989
TGRCDev (TGRCdev)

documentation

README

select_indices

GitHub Workflow Status crates.io docs.rs Crates.io

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

use select_indices::prelude::*;

fn main()
{
    struct BankAccount {
        pub name: String,
        pub balance: f32,
    }
    
    let mut vec: Vec<BankAccount> = 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.

Commit count: 47

cargo fmt