pub struct IdxBox<Idx> { /* private fields */ }Expand description
An allocation of bounded indices that can be retrieved with a bound.
The usefulness comes from the fact that there is not tag on the type but instead one is assigned when retrieving the contents. In particular you don’t need a unique type to construct this container.
Implementations§
Source§impl<I: HiddenMaxIndex> IdxBox<I>
impl<I: HiddenMaxIndex> IdxBox<I>
Sourcepub fn new(indices: Box<[I]>) -> Result<Self, Box<[I]>>
pub fn new(indices: Box<[I]>) -> Result<Self, Box<[I]>>
Wrap an allocation of indices.
This will fail if it not possible to express the lower bound of slices for which all
indices are valid, as a usize. That is, if any of the indices references the element
with index usize::MAX itself.
Sourcepub fn bound(&self) -> usize
pub fn bound(&self) -> usize
Return the upper bound over all indices. This is not guaranteed to be the least upper bound.
Sourcepub fn truncate(&mut self)
pub fn truncate(&mut self)
Set the bound to the least upper bound of all indices.
This always reduces the bound and there can not be any lower bound that is consistent
with all indices stored in this IdxBox.
Sourcepub fn as_ref<T: Tag>(&self, size: Prefix<T>) -> Option<&[Idx<I, T>]>
pub fn as_ref<T: Tag>(&self, size: Prefix<T>) -> Option<&[Idx<I, T>]>
Reinterpret the contents as indices of a given tag.
The given size must not be smaller than the bound of this allocated. This guarantees
that all indices within the box are valid for the Tag. Since you can only view the
indices, they will remain valid.
Sourcepub fn as_mut<T: Tag>(&mut self, size: ExactSize<T>) -> Option<&mut [Idx<I, T>]>
pub fn as_mut<T: Tag>(&mut self, size: ExactSize<T>) -> Option<&mut [Idx<I, T>]>
Reinterpret the contents as mutable indices of a given tag.
The given exact size must not be exactly the same as the bound of this allocated
slice. This guarantees that all indices within the box are valid for the Tag, and that
all stored indices will be valid for all future tags.