From 44917baba78dff59fe4363d472f743e302db20e0 Mon Sep 17 00:00:00 2001 From: Sludge <96552222+SludgePhD@users.noreply.github.com> Date: Sun, 3 Sep 2023 15:26:13 +0200 Subject: [PATCH] Add `DiagnosticsStore::iter_mut` (#9679) # Objective Allow mutably iterating over all registered diagnostics. This is a useful utility method when exposing bevy's diagnostics in an editor that allows toggling whether the diagnostic is enabled. ## Solution - Add `iter_mut`, mirroring what `iter` does, just mutably. --- ## Changelog ### Added - Added `DiagnosticsStore::iter_mut` for mutably iterating over all registered diagnostics. --- crates/bevy_diagnostic/src/diagnostic.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/bevy_diagnostic/src/diagnostic.rs b/crates/bevy_diagnostic/src/diagnostic.rs index 6fa04ce573f20..693642c5d6a39 100644 --- a/crates/bevy_diagnostic/src/diagnostic.rs +++ b/crates/bevy_diagnostic/src/diagnostic.rs @@ -227,10 +227,15 @@ impl DiagnosticsStore { .and_then(|diagnostic| diagnostic.measurement()) } - /// Return an iterator over all [`Diagnostic`]. + /// Return an iterator over all [`Diagnostic`]s. pub fn iter(&self) -> impl Iterator { self.diagnostics.values() } + + /// Return an iterator over all [`Diagnostic`]s, by mutable reference. + pub fn iter_mut(&mut self) -> impl Iterator { + self.diagnostics.values_mut() + } } /// Record new [`DiagnosticMeasurement`]'s.