rust/lib-hedgewars-engine/src/ipc.rs
changeset 14277 3152d9fdb499
parent 14266 1b8c889027a3
child 14299 21be7838a127
--- a/rust/lib-hedgewars-engine/src/ipc.rs	Thu Nov 22 10:58:55 2018 +0100
+++ b/rust/lib-hedgewars-engine/src/ipc.rs	Thu Nov 22 13:39:51 2018 +0100
@@ -18,6 +18,10 @@
     pub fn send_message(&mut self, message: &EngineMessage) {
         self.out_buffer.write(&message.to_bytes()).unwrap();
     }
+
+    pub fn iter(& mut self) -> IPCMessagesIterator {
+        IPCMessagesIterator::new(self)
+    }
 }
 
 impl Write for IPC {
@@ -40,13 +44,25 @@
     }
 }
 
-impl Iterator for IPC {
+pub struct IPCMessagesIterator<'a> {
+    ipc: &'a mut IPC
+}
+
+impl<'a> IPCMessagesIterator<'a> {
+    pub fn new(ipc: &'a mut IPC) -> Self {
+        Self {
+            ipc
+        }
+    }
+}
+
+impl<'a> Iterator for IPCMessagesIterator<'a> {
     type Item = EngineMessage;
 
     fn next(&mut self) -> Option<Self::Item> {
-        let (consumed, message) = extract_message(&self.in_buffer[..])?;
+        let (consumed, message) = extract_message(&self.ipc.in_buffer[..])?;
 
-        self.in_buffer.consume(consumed);
+        self.ipc.in_buffer.consume(consumed);
 
         Some(message)
     }