pub struct Array<S, const N: usize> { /* private fields */ }Expand description
A fixed-length array of N storage slots of type S.
Element i lives at the array’s keypath extended by i as a u32 — the
same slot Map<u32, S> at that keypath would use for key
i, so the two layouts are interchangeable. Like Map, an Array holds
only its own keypath and derives an element’s key when the element is
accessed, so its size and load cost do not depend on N. Unlike Map, the
length is known at compile time: indexing is bounds-checked without a
storage read, and the array can enumerate (iterate and delete) its
elements.
Unlike Vector, there is no stored length: every index
in 0..N is always in bounds, and an element that was never written (or
was deleted) reads back as missing. Read with try_get +
none_if_missing when an
element may be unset. Elements share no storage, so writes to distinct
elements never conflict with each other.
N must fit in a u32; a larger N fails to compile on first use.
Implementations§
Source§impl<S: StorageType, const N: usize> Array<S, N>
impl<S: StorageType, const N: usize> Array<S, N>
Sourcepub fn at_mut(&mut self, index: u32) -> SlotMut<'_, Self, S>
pub fn at_mut(&mut self, index: u32) -> SlotMut<'_, Self, S>
Mutably borrow element at index (bounds-checked).
Sourcepub fn at_mut_exclusive(&mut self, index: u32) -> SlotMut<'_, Self, S>
pub fn at_mut_exclusive(&mut self, index: u32) -> SlotMut<'_, Self, S>
Like at_mut, but every successful write through the
returned handle is followed by a request for an exclusive lock on the
element. See Map::at_mut_exclusive.
Sourcepub fn at_disjoint_mut<const M: usize>(
&mut self,
indices: [u32; M],
) -> DisjointMut<'_, Self, S, M>
pub fn at_disjoint_mut<const M: usize>( &mut self, indices: [u32; M], ) -> DisjointMut<'_, Self, S, M>
Mutably borrow M elements at once (bounds-checked). Panics if any indices are equal.
See Map::at_disjoint_mut.
Sourcepub fn iter(&self) -> ArrayIter<'_, S, N> ⓘ
pub fn iter(&self) -> ArrayIter<'_, S, N> ⓘ
Iterate over all N elements. Yields read-only SlotRef handles,
deriving each element’s key as it is reached.
Sourcepub fn iter_mut(&mut self) -> ArrayIterMut<'_, S, N> ⓘ
pub fn iter_mut(&mut self) -> ArrayIterMut<'_, S, N> ⓘ
Iterate over all N elements with mutable access. Holds an exclusive
borrow on the array.