multi-array-list 0.1.0

A `MultiArrayList` stores a list of a struct.
Documentation
  • Coverage
  • 100%
    16 out of 16 items documented2 out of 16 items with examples
  • Size
  • Source code size: 28.42 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.43 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • badboy

MultiArrayList

Experimental: Only a small subset of a the array list API is implemented.


A MultiArrayList stores a list of a struct.

Instead of storing a single list of items, MultiArrayList stores separate lists for each field of the struct. This allows for memory savings if the struct has padding, and also improves cache usage if only some fields are needed for a computation.

The primary API for accessing fields is the [items(name)][MultiArrayList::items()] function.


inspired by Zig's MultiArrayList.

Example

use multi_array_list::MultiArrayList;
use facet::Facet;

#[derive(Facet, Clone)]
struct Pizza {
    radius: u32,
    toppings: Vec<Topping>,
}

#[derive(Facet, Clone, Copy)]
#[repr(u8)]
enum Topping {
    Tomato,
    Mozzarella,
    Anchovies,
}

let mut order = MultiArrayList::<Pizza>::new();

let margherita = Pizza {
    radius: 12,
    toppings: vec![Topping::Tomato],
};
order.push(margherita);

let napoli = Pizza {
    radius: 12,
    toppings: vec![Topping::Tomato, Topping::Anchovies],
};
order.push(napoli);

for topping in order.items_mut::<Vec<Topping>>("toppings") {
    topping.push(Topping::Mozzarella);
}

License

MIT. See LICENSE.