IdxBox

Struct IdxBox 

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

Source

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.

Source

pub fn bound(&self) -> usize

Return the upper bound over all indices. This is not guaranteed to be the least upper bound.

Source

pub fn ensure(&mut self, min: usize)

Ensure that the stored bound is at least min.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<Idx> Freeze for IdxBox<Idx>

§

impl<Idx> RefUnwindSafe for IdxBox<Idx>
where Idx: RefUnwindSafe,

§

impl<Idx> Send for IdxBox<Idx>
where Idx: Send,

§

impl<Idx> Sync for IdxBox<Idx>
where Idx: Sync,

§

impl<Idx> Unpin for IdxBox<Idx>

§

impl<Idx> UnwindSafe for IdxBox<Idx>
where Idx: 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.