From 88003c299775883e50358e9b5de9235471b93725 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Tue, 5 Sep 2023 00:17:48 +0300 Subject: [PATCH] modify IntoIterator that now it yields (id, &Entity) --- src/fot/entitylist.rs | 10 +++++----- src/fot/world.rs | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/fot/entitylist.rs b/src/fot/entitylist.rs index a5bfbaf..7e86058 100644 --- a/src/fot/entitylist.rs +++ b/src/fot/entitylist.rs @@ -26,8 +26,8 @@ pub struct EntityList { unk1: u32, enc_size: usize, - pub types: Vec, - pub ents: Vec, + types: Vec, + ents: Vec, } impl EntityList { @@ -161,10 +161,10 @@ impl DecoderCtx for EntityList { } impl<'a> IntoIterator for &'a EntityList { - type Item = &'a Entity; - type IntoIter = std::slice::Iter<'a, Entity>; + type Item = (usize, &'a Entity); + type IntoIter = std::iter::Zip, std::slice::Iter<'a, Entity>>; fn into_iter(self) -> Self::IntoIter { - self.ents.iter() + (1..).zip(&self.ents) } } \ No newline at end of file diff --git a/src/fot/world.rs b/src/fot/world.rs index 98aa7d0..1f56e4f 100644 --- a/src/fot/world.rs +++ b/src/fot/world.rs @@ -37,8 +37,8 @@ impl World { self.entlist .encode(EntityEncoding::File)? .dump(Path::new("D:\\entlist.ent"))?;*/ - for ent in &self.entlist { - println!("{}", ent.type_idx); + for (id, ent) in &self.entlist { + println!("{} {}", id, ent.type_idx); } Ok(())