From efa17e7eb566d81ce821bde459e900d7398a9977 Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Sat, 21 Nov 2026 21:05:57 -0700 Subject: facilities now get an update ping at the start of each frame with that done, battery status now updates live! wooooo Force-Push: yes Change-Id: If7f2343f6d7762e8f65a4735deadc1b871e26f9d --- src/facility.rs | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) (limited to 'src/facility.rs') diff --git a/src/facility.rs b/src/facility.rs index c156570..dcc252c 100644 --- a/src/facility.rs +++ b/src/facility.rs @@ -21,6 +21,11 @@ pub trait Facility: Any { */ #[allow(dead_code)] fn as_any_mut(&mut self) -> &mut dyn Any; + + /* Frustratingly, this can't be async because that wouldn't be + * dyn-compatible. + */ + fn update(&mut self) -> Result<()>; } /* In order to keep Facility dyn-compatible, we put everything that isn't in @@ -106,5 +111,48 @@ impl FacilityMap { (*facility).as_mut().as_any_mut().downcast_mut() } else { None } } + + pub fn iter(&self) -> impl Iterator> { + let btree_iterator = self.facilities.iter(); + + Iter { btree_iterator } + } + + pub fn iter_mut(&mut self) -> impl Iterator> { + let btree_iterator = self.facilities.iter_mut(); + + IterMut { btree_iterator } + } +} + + +struct Iter<'a> { + btree_iterator: std::collections::btree_map + ::Iter<'a, FacilityType, Box>, +} + +impl<'a> Iterator for Iter<'a> { + type Item = &'a Box; + + fn next(&mut self) -> Option { + if let Some((_, value)) = self.btree_iterator.next() { + Some(value) + } else { None } + } +} + +struct IterMut<'a> { + btree_iterator: std::collections::btree_map + ::IterMut<'a, FacilityType, Box>, +} + +impl<'a> Iterator for IterMut<'a> { + type Item = &'a mut Box; + + fn next(&mut self) -> Option { + if let Some((_, value)) = self.btree_iterator.next() { + Some(value) + } else { None } + } } -- cgit 1.4.1