chiark / gitweb /
bundles: Break out InstanceBundles::iter()
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 May 2021 14:50:06 +0000 (15:50 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 3 May 2021 14:50:30 +0000 (15:50 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/bundles.rs

index 0d003595b9e0285cf434e125814e420b70b9b962..e131d7a529c22045b892cbdd61c2b40fe7e7dc00 100644 (file)
@@ -203,12 +203,17 @@ fn incorporate_bundle(ib: &mut InstanceBundles, ig: &mut Instance,
 impl InstanceBundles {
   pub fn new() -> Self { InstanceBundles{ bundles: default() } }
 
-  pub fn list(&self) -> MgmtBundleList {
+  fn iter(&self) -> impl Iterator<Item=(Id, &State)> {
     self.bundles.iter().enumerate().filter_map(|(index, slot)| {
-      let note = slot.as_ref()?;
+      let Note { kind, ref state } = *slot.as_ref()?;
       let index = index.try_into().unwrap();
-      Some((Id { index, kind: note.kind },
-            note.state.clone()))
+      Some((Id { index, kind }, state))
+    })
+  }
+
+  pub fn list(&self) -> MgmtBundleList {
+    self.iter().map(|(id, state)| {
+      (id, state.clone())
     }).collect()
   }