mirror of
https://github.com/neocturne/MinedMap.git
synced 2025-07-02 13:59:07 +02:00
world: introduce SectionIterItem struct
This commit is contained in:
parent
ed422be451
commit
47dc3795a3
3 changed files with 24 additions and 14 deletions
|
@ -182,16 +182,19 @@ impl<'a> Chunk<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct SectionIterItem<'a> {
|
||||
pub y: SectionY,
|
||||
pub section: &'a dyn Section,
|
||||
}
|
||||
|
||||
trait SectionIterTrait<'a>:
|
||||
Iterator<Item = (SectionY, &'a dyn Section)>
|
||||
+ DoubleEndedIterator
|
||||
+ ExactSizeIterator
|
||||
+ FusedIterator
|
||||
Iterator<Item = SectionIterItem<'a>> + DoubleEndedIterator + ExactSizeIterator + FusedIterator
|
||||
{
|
||||
}
|
||||
|
||||
impl<'a, T> SectionIterTrait<'a> for T where
|
||||
T: Iterator<Item = (SectionY, &'a dyn Section)>
|
||||
T: Iterator<Item = SectionIterItem<'a>>
|
||||
+ DoubleEndedIterator
|
||||
+ ExactSizeIterator
|
||||
+ FusedIterator
|
||||
|
@ -204,14 +207,15 @@ impl<'a> SectionIter<'a> {
|
|||
F: FnOnce(&mut dyn SectionIterTrait<'a>) -> T,
|
||||
{
|
||||
match &mut self.inner {
|
||||
SectionIterInner::V1_18 { iter } => f(
|
||||
&mut iter.map(|(y, section)| -> (SectionY, &'a dyn Section) { (*y, §ion.0) })
|
||||
),
|
||||
SectionIterInner::V1_18 { iter } => f(&mut iter.map(|(&y, section)| SectionIterItem {
|
||||
y,
|
||||
section: §ion.0,
|
||||
})),
|
||||
SectionIterInner::V1_13 { iter } => {
|
||||
f(&mut iter.map(|(y, section)| -> (SectionY, &'a dyn Section) { (*y, section) }))
|
||||
f(&mut iter.map(|(&y, section)| SectionIterItem { y, section }))
|
||||
}
|
||||
SectionIterInner::V0 { iter } => {
|
||||
f(&mut iter.map(|(y, section)| -> (SectionY, &'a dyn Section) { (*y, section) }))
|
||||
f(&mut iter.map(|(&y, section)| SectionIterItem { y, section }))
|
||||
}
|
||||
SectionIterInner::Empty => f(&mut iter::empty()),
|
||||
}
|
||||
|
@ -219,7 +223,7 @@ impl<'a> SectionIter<'a> {
|
|||
}
|
||||
|
||||
impl<'a> Iterator for SectionIter<'a> {
|
||||
type Item = (SectionY, &'a dyn Section);
|
||||
type Item = SectionIterItem<'a>;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.with_iter(|iter| iter.next())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue