1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use super::super::super::box2d::dynamics::body::*;
use super::super::super::box2d::dynamics::world::*;

pub struct BodyIterator {
	body: Option<Body>,
	started: bool
}

impl World {
	/// Get a world body iterator.
	pub fn get_body_iterator(&mut self) -> BodyIterator {
		BodyIterator { body: self.get_body_list(), started: false }
	}
}

impl Iterator for BodyIterator {
	type Item = Body;
	fn next(&mut self) -> Option<Body> {
		if  !self.started {
			self.started = true;
		} else {
			self.body = match self.body {
				Some(ref x) => x.get_next(),
				None => None
			}
		}

		self.body.clone()
	}
}