Skip to content

Commit

Permalink
Add panics sections to doc strings
Browse files Browse the repository at this point in the history
  • Loading branch information
nakedible committed Jul 27, 2023
1 parent 0a6e07f commit 7858e70
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
24 changes: 24 additions & 0 deletions crates/bevy_time/src/fixed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,32 @@ impl Time<Fixed> {

/// 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);
ret
}

/// 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);
ret
}

/// 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);
Expand All @@ -102,6 +114,10 @@ impl Time<Fixed> {
///
/// 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!(
Expand All @@ -121,6 +137,10 @@ impl Time<Fixed> {
///
/// 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!(
Expand All @@ -139,6 +159,10 @@ impl Time<Fixed> {
///
/// 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");
Expand Down
8 changes: 8 additions & 0 deletions crates/bevy_time/src/virt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ impl Time<Virtual> {

/// 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);
Expand Down Expand Up @@ -125,6 +129,10 @@ impl Time<Virtual> {
///
/// 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");
Expand Down

0 comments on commit 7858e70

Please sign in to comment.