From d7a60884e36f2a252df35a62aae15b0d2bc538dd Mon Sep 17 00:00:00 2001 From: Nuutti Kotivuori Date: Thu, 27 Jul 2023 20:52:53 +0000 Subject: [PATCH] Add panics sections to doc strings --- crates/bevy_time/src/fixed.rs | 24 ++++++++++++++++++++++++ crates/bevy_time/src/virt.rs | 8 ++++++++ 2 files changed, 32 insertions(+) diff --git a/crates/bevy_time/src/fixed.rs b/crates/bevy_time/src/fixed.rs index 647776d63b3623..d433a5f4a7fc32 100644 --- a/crates/bevy_time/src/fixed.rs +++ b/crates/bevy_time/src/fixed.rs @@ -70,6 +70,10 @@ impl Time { /// Return new fixed time clock with given timestep as /// [`Duration`](std::time::Duration) + /// + /// # Panics + /// + /// Panics if `timestep` is zero. pub fn from_duration(timestep: Duration) -> Self { let mut ret = Self::default(); ret.set_timestep(timestep); @@ -77,6 +81,10 @@ impl Time { } /// Return new fixed time clock with given timestep seconds as `f64` + /// + /// # Panics + /// + /// Panics if `seconds` is negative or not finite. pub fn from_seconds(seconds: f64) -> Self { let mut ret = Self::default(); ret.set_timestep_seconds(seconds); @@ -84,6 +92,10 @@ impl Time { } /// Return new fixed time clock with given timestep frequency in Hertz (1/seconds) + /// + /// # Panics + /// + /// Panics if `hz` is zero, negative or not finite. pub fn from_hz(hz: f64) -> Self { let mut ret = Self::default(); ret.set_timestep_hz(hz); @@ -102,6 +114,10 @@ impl Time { /// /// Takes effect immediately on the next run of the schedule, respecting /// what is currently in [`Self::overstep`]. + /// + /// # Panics + /// + /// Panics if `timestep` is zero. #[inline] pub fn set_timestep(&mut self, timestep: Duration) { assert_ne!( @@ -121,6 +137,10 @@ impl Time { /// /// Takes effect immediately on the next run of the schedule, respecting /// what is currently in [`Self::overstep`]. + /// + /// # Panics + /// + /// Panics if `seconds` is negative or not finite. #[inline] pub fn set_timestep_seconds(&mut self, seconds: f64) { assert!( @@ -139,6 +159,10 @@ impl Time { /// /// Takes effect immediately on the next run of the schedule, respecting /// what is currently in [`Self::overstep`]. + /// + /// # Panics + /// + /// Panics if `hz` is zero, negative or not finite. #[inline] pub fn set_timestep_hz(&mut self, hz: f64) { assert!(hz.is_sign_positive(), "Hz less than or equal to zero"); diff --git a/crates/bevy_time/src/virt.rs b/crates/bevy_time/src/virt.rs index ceee43723eda7d..fa0123d850053d 100644 --- a/crates/bevy_time/src/virt.rs +++ b/crates/bevy_time/src/virt.rs @@ -84,6 +84,10 @@ impl Time { /// Create new virtual clock with given maximum delta step /// [`Duration`](std::time::Duration) + /// + /// # Panics + /// + /// Panics if `max_delta` is zero. pub fn from_max_delta(max_delta: Duration) -> Self { let mut ret = Self::default(); ret.set_max_delta(max_delta); @@ -125,6 +129,10 @@ impl Time { /// /// The default value is 250 milliseconds. If you want to disable this feature, /// set the value to [`Duration::MAX`](std::time::Duration). + /// + /// # Panics + /// + /// Panics if `max_delta` is zero. #[inline] pub fn set_max_delta(&mut self, max_delta: Duration) { assert_ne!(max_delta, Duration::ZERO, "tried to set max delta to zero");