//! The [`HandleVec`] type and associated definitions.
usesuper::handle::Handle;
use std::marker::PhantomData; use std::ops;
/// A [`Vec`] indexed by [`Handle`]s. /// /// A `HandleVec<T, U>` is a [`Vec<U>`] indexed by values of type `Handle<T>`, /// rather than `usize`. /// /// Rather than a `push` method, `HandleVec` has an [`insert`] method, analogous /// to [`HashMap::insert`], that requires you to provide the handle at which the /// new value should appear. However, since `HandleVec` only supports insertion /// at the end, the given handle's index must be equal to the the `HandleVec`'s /// current length; otherwise, the insertion will panic. /// /// [`insert`]: HandleVec::insert /// [`HashMap::insert`]: std::collections::HashMap::insert #[derive(Debug)] pub(crate) struct HandleVec<T, U> {
inner: Vec<U>,
as_keys: PhantomData<T>,
}
/// Insert a mapping from `handle` to `value`. /// /// Unlike a [`HashMap`], a `HandleVec` can only have new entries inserted at /// the end, like [`Vec::push`]. So the index of `handle` must equal /// [`self.len()`]. /// /// [`HashMap`]: std::collections::HashMap /// [`self.len()`]: HandleVec::len pub(crate) fn insert(&mutself, handle: Handle<T>, value: U) {
assert_eq!(handle.index(), self.inner.len()); self.inner.push(value);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.