pub struct MultiArrayList<T>{ /* private fields */ }Expand description
A MultiArrayList stores a list of a struct.
Instead of storing a single list of items,
MultiArrayListstores 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) function.
Implementations§
Source§impl<T> MultiArrayList<T>
impl<T> MultiArrayList<T>
Sourcepub fn new() -> MultiArrayList<T>
pub fn new() -> MultiArrayList<T>
Constructs a new, empty MultiArrayList<T>.
§Examples
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
struct Point {
x: i32,
y: i32
}
let mut list: MultiArrayList<Point> = MultiArrayList::new();§Type can’t be not a struct
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
use multi_array_list::MultiArrayList;
#[repr(u8)]
enum Random {
Four,
}
let m = MultiArrayList::<Random>::new();§Type can’t be empty
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
use multi_array_list::MultiArrayList;
let m = MultiArrayList::<()>::new();Sourcepub fn with_capacity(capacity: usize) -> MultiArrayList<T>
pub fn with_capacity(capacity: usize) -> MultiArrayList<T>
Constructs a new, empty MultiArrayList<T> with at least the specified capacity.
§Examples
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
struct Point {
x: i32,
y: i32
}
let mut list: MultiArrayList<Point> = MultiArrayList::with_capacity(10);Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the total number of elements the vector can hold without reallocating.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the MultiArrayList, also referred to as its ‘length’.
Sourcepub fn pop(&mut self) -> Option<Box<T>>
pub fn pop(&mut self) -> Option<Box<T>>
Removes the last element from the MultiArrayList and returns it, or None if it is empty.
Sourcepub fn iter<'a>(&'a self) -> Iter<'a, T> ⓘ
pub fn iter<'a>(&'a self) -> Iter<'a, T> ⓘ
Returns an iterator over the MultiArrayList.
The iterator yields all items from start to end.
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
use multi_array_list::MultiArrayList;
struct Point {
x: i32,
y: i32,
}
let mut points = MultiArrayList::<Point>::new();
points.push(Point { x: 1, y: 0 });
for point in points.iter() {
assert_eq!(1, *point.get::<"x", _>());
assert_eq!(0, *point.get::<"y", _>());
}Sourcepub fn items<'a, const NAME: &'static str, V: 'static>(&'a self) -> Slice<'a, V> ⓘ
pub fn items<'a, const NAME: &'static str, V: 'static>(&'a self) -> Slice<'a, V> ⓘ
Get an iterator of values for a specified field.
§Compile errors
- Fails to compile if the requested field does not exist.
- Fails to compile if the requested type does not match the found field (by size).
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
use multi_array_list::MultiArrayList;
struct HereBeDragons {
x: u32,
y: (u8, u16),
}
let mut list = MultiArrayList::<HereBeDragons>::new();
_ = list.items::<"y", (u16, u8)>(); // will not compileSourcepub fn items_mut<'a, const NAME: &'static str, V: 'static>(
&'a mut self,
) -> SliceMut<'a, V> ⓘ
pub fn items_mut<'a, const NAME: &'static str, V: 'static>( &'a mut self, ) -> SliceMut<'a, V> ⓘ
Get an iterator of mutable values for a specified field.
§Compile errors
- Fails to compile if the requested field does not exist.
- Fails to compile if the requested type does not match the found field (by size).
Sourcepub fn shrink_to_fit(&mut self)
pub fn shrink_to_fit(&mut self)
Shrinks the capacity of the vector as much as possible.