From 201b51e85cf38177e1c80cfc475bade98d9c9421 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Tue, 5 Sep 2023 00:04:54 +0300 Subject: [PATCH] impl IntoIterator for EntityList, so entities can be easily iterated --- src/fot/entitylist.rs | 9 +++++++++ src/fot/world.rs | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/fot/entitylist.rs b/src/fot/entitylist.rs index ac8f185..a5bfbaf 100644 --- a/src/fot/entitylist.rs +++ b/src/fot/entitylist.rs @@ -159,3 +159,12 @@ impl DecoderCtx for EntityList { self.enc_size } } + +impl<'a> IntoIterator for &'a EntityList { + type Item = &'a Entity; + type IntoIter = std::slice::Iter<'a, Entity>; + + fn into_iter(self) -> Self::IntoIter { + self.ents.iter() + } +} \ No newline at end of file diff --git a/src/fot/world.rs b/src/fot/world.rs index 8b7f011..98aa7d0 100644 --- a/src/fot/world.rs +++ b/src/fot/world.rs @@ -37,6 +37,9 @@ impl World { self.entlist .encode(EntityEncoding::File)? .dump(Path::new("D:\\entlist.ent"))?;*/ + for ent in &self.entlist { + println!("{}", ent.type_idx); + } Ok(()) }