Skip to content

Commit

Permalink
Appease the great and might clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
DJMcNab committed Sep 25, 2024
1 parent b9a90ff commit 4e11b7a
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions examples/with_winit/src/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,6 @@ pub struct Snapshot {
pub frame_time_max_ms: f64,
}

/// Formats the given number of seconds as a Duration.
///
/// This is necessary as sometimes, the duration from wgpu-profiler turns out to be negative.
/// We have not yet debugged this, but we choose to display the absolute
/// value in that case.
///
/// See <https://github.com/linebender/vello/pull/475> for context
struct PaniclessSecondsFormatter(f64);

impl Display for PaniclessSecondsFormatter {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.0 < 0. {
if let Ok(val) = Duration::try_from_secs_f64(-self.0) {
return write!(f, "-{val:.2?}(!)");
}
} else if let Ok(val) = Duration::try_from_secs_f64(self.0) {
return write!(f, "{val:.2?}");
}
write!(f, "{} seconds(!)", self.0)
}
}

impl Snapshot {
#[allow(clippy::too_many_arguments)]
pub fn draw_layer<'a, T>(
Expand Down Expand Up @@ -273,6 +251,30 @@ fn round_up(n: usize, f: usize) -> usize {
#[cfg(feature = "wgpu-profiler")]
use wgpu_profiler::GpuTimerQueryResult;

/// Formats the given number of seconds as a Duration.
///
/// This is necessary as sometimes, the duration from wgpu-profiler turns out to be negative.
/// We have not yet debugged this, but we choose to display the absolute
/// value in that case.
///
/// See <https://github.com/linebender/vello/pull/475> for context
#[cfg(feature = "wgpu-profiler")]
struct PaniclessSecondsFormatter(f64);

#[cfg(feature = "wgpu-profiler")]
impl Display for PaniclessSecondsFormatter {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.0 < 0. {
if let Ok(val) = Duration::try_from_secs_f64(-self.0) {
return write!(f, "-{val:.2?}(!)");
}
} else if let Ok(val) = Duration::try_from_secs_f64(self.0) {
return write!(f, "{val:.2?}");
}
write!(f, "{} seconds(!)", self.0)
}
}

#[cfg(feature = "wgpu-profiler")]
fn profiles_are_empty(profiles: &[GpuTimerQueryResult]) -> bool {
profiles.iter().all(|p| p.time.is_none())
Expand Down

0 comments on commit 4e11b7a

Please sign in to comment.