Skip to content

Commit

Permalink
Add DiagnosticsStore::iter_mut (#9679)
Browse files Browse the repository at this point in the history
# 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.
  • Loading branch information
SludgePhD authored Sep 3, 2023
1 parent 532f3cb commit ae8a4a8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion crates/bevy_diagnostic/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = &Diagnostic> {
self.diagnostics.values()
}

/// Return an iterator over all [`Diagnostic`]s, by mutable reference.
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut Diagnostic> {
self.diagnostics.values_mut()
}
}

/// Record new [`DiagnosticMeasurement`]'s.
Expand Down

0 comments on commit ae8a4a8

Please sign in to comment.