//! Well-typed ranges of [`Arena`]s. //! //! This module defines the [`Range`] type, representing a contiguous range of //! entries in an [`Arena`]. //! //! [`Arena`]: super::Arena
// NOTE: Keep this diagnostic in sync with that of [`BadHandle`]. #[derive(Clone, Debug, thiserror::Error)] #[cfg_attr(test, derive(PartialEq))] #[error("Handle range {range:?} of {kind} is either not present, or inaccessible yet")] pubstruct BadRangeError { // This error is used for many `Handle` types, but there's no point in making this generic, so // we just flatten them all to `Handle<()>` here.
kind: &'static str,
range: Range<()>,
}
impl<T> Iterator for Range<T> { type Item = Handle<T>; fn next(&mutself) -> Option<Self::Item> { ifself.inner.start < self.inner.end { let next = self.inner.start; self.inner.start += 1;
Some(Handle::new(Index::new(next).unwrap()))
} else {
None
}
}
}
impl<T> Range<T> { /// Return a range enclosing handles `first` through `last`, inclusive. pubfn new_from_bounds(first: Handle<T>, last: Handle<T>) -> Self { Self {
inner: (first.index() as u32)..(last.index() as u32 + 1),
marker: Default::default(),
}
}
/// Return a range covering all handles with indices from `0` to `size`. pub(super) fn full_range_from_size(size: usize) -> Self { Self {
inner: 0..size as u32,
marker: Default::default(),
}
}
/// return the first and last handles included in `self`. /// /// If `self` is an empty range, there are no handles included, so /// return `None`. pubfn first_and_last(&self) -> Option<(Handle<T>, Handle<T>)> { ifself.inner.start < self.inner.end {
Some(( // `Range::new_from_bounds` expects a start- and end-inclusive // range, but `self.inner` is an end-exclusive range.
Handle::new(Index::new(self.inner.start).unwrap()),
Handle::new(Index::new(self.inner.end - 1).unwrap()),
))
} else {
None
}
}
/// Return the index range covered by `self`. pubfn index_range(&self) -> ops::Range<u32> { self.inner.clone()
}
/// Construct a `Range` that covers the indices in `inner`. pubfn from_index_range(inner: ops::Range<u32>, arena: &Arena<T>) -> Self { // Since `inner` is a `Range<u32>`, we only need to check that // the start and end are well-ordered, and that the end fits // within `arena`.
assert!(inner.start <= inner.end);
assert!(inner.end as usize <= arena.len()); Self {
inner,
marker: Default::default(),
}
}
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-18)
¤
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.