Add ObjectSet::before

This commit is contained in:
Hanno Braun 2024-06-28 18:00:56 +02:00
parent 7bccd67394
commit 80828e28cb

View File

@ -121,6 +121,14 @@ impl<T> ObjectSet<T> {
self.inner.iter().position(|h| h.id() == handle.id())
}
/// Access the item before the provided one
///
/// Returns `None`, if the provided item is not in this set.
pub fn before(&self, handle: &Handle<T>) -> Option<&Handle<T>> {
self.index_of(handle)
.map(|index| self.nth_circular(index + self.len() - 1))
}
/// Access the item after the provided one
///
/// Returns `None`, if the provided item is not in this set.