qindex_multi 0.2.0

Provides means of indexing collections mutable and immutable multiple times at once.
docs.rs failed to build qindex_multi-0.2.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.

qindex_multi

API Documentation

This crate provides MultiIndexable, through which its implementors allow us to violate basic borrowing-rules when indexing them (using Index[Mut]) , as long as we adhere to them for each individual element.

In other words: We can index a collection mutably and immutable multiple times at once, as long as there are no read/write clashes.

NOTE: MultiIndexable is currently not implemented for libstd's HashMap and BTreeMap, due to them missing IndexMut-implementations. This will change when IndexAssign-functionality lands.

This crate requires the latest rust nightly to compile.

TODO

  • Doc, Tests, Examples

Example Usage

#![feature(slice_patterns)]

extern crate qcollect;
extern crate qindex_multi;
extern crate vec_map;

use vec_map::VecMap;
use qindex_multi::{MultiIndexable, MultiIndex};

#[test]
fn test1(){
    let mut data = VecMap::new();
    data.insert(0, 100u16); 
    data.insert(2, 200);
    data.insert(20, 300);
    data.insert(200, 400);

    let read_indicies = vec![0, 2, 20];
    let write_indicies = vec![200];

    let multi_idx = MultiIndex::new(read_indicies, write_indicies);

    {
        let mut output = data.index_multi(&multi_idx);
        
        let [a, b, c]: [_; 3] = qcollect::iter_into_fixed(output.read);
        let d = output.write.next().unwrap();
        *d += *a + *b + c; 
        
    }
    assert_eq!(data[200], 1000);
}