use crate::{
archetype,
entity::allocator::Location,
registry::Registry,
};
use core::ops::Range;
pub(crate) struct Locations<R>
where
R: Registry,
{
indices: Range<usize>,
identifier: archetype::IdentifierRef<R>,
}
impl<R> Locations<R>
where
R: Registry,
{
pub(crate) fn new(indices: Range<usize>, identifier: archetype::IdentifierRef<R>) -> Self {
Self {
indices,
identifier,
}
}
pub(super) fn len(&self) -> usize {
debug_assert!(self.indices.end >= self.indices.start);
self.indices.end - self.indices.start
}
pub(super) fn is_empty(&self) -> bool {
self.indices.is_empty()
}
}
impl<R> Iterator for Locations<R>
where
R: Registry,
{
type Item = Location<R>;
fn next(&mut self) -> Option<Self::Item> {
self.indices.next().map(|index| Location {
identifier: self.identifier,
index,
})
}
}