Skip to main content

MultiArrayList

Struct MultiArrayList 

Source
pub struct MultiArrayList<T>
where T: 'static, [(); { _ }]:,
{ /* private fields */ }
Expand description

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) function.

Implementations§

Source§

impl<T> MultiArrayList<T>
where T: 'static, [(); { _ }]:,

Source

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();
Source

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);
Source

pub fn capacity(&self) -> usize

Returns the total number of elements the vector can hold without reallocating.

Source

pub fn len(&self) -> usize

Returns the number of elements in the MultiArrayList, also referred to as its ‘length’.

Source

pub fn push(&mut self, value: T)

Appends an element to the back of a collection.

Source

pub fn pop(&mut self) -> Option<Box<T>>

Removes the last element from the MultiArrayList and returns it, or None if it is empty.

Source

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", _>());
}
Source

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 compile
Source

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).
Source

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the vector as much as possible.

Trait Implementations§

Source§

impl<T> Debug for MultiArrayList<T>
where T: 'static + Debug, [(); { _ }]:,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Drop for MultiArrayList<T>
where T: 'static, [(); { _ }]:,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for MultiArrayList<T>

§

impl<T> RefUnwindSafe for MultiArrayList<T>
where T: RefUnwindSafe,

§

impl<T> !Send for MultiArrayList<T>

§

impl<T> !Sync for MultiArrayList<T>

§

impl<T> Unpin for MultiArrayList<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for MultiArrayList<T>

§

impl<T> UnwindSafe for MultiArrayList<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.