Skip to content

Commit

Permalink
Add DiagnosticsStore::iter_mut (bevyengine#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 and Ray Redondo committed Jan 9, 2024
1 parent 7575747 commit 44917ba
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 44917ba

Please sign in to comment.