Struct spin_sleep::LoopHelper [−][src]
pub struct LoopHelper { /* fields omitted */ }Tool for loop rate reporting and control.
Can report mean rate per second of a loop over a configured
report interval with LoopHelper::report_rate.
Can limit a loop rate to a desired target using
LoopHelper::loop_sleep.
Example
use spin_sleep::LoopHelper; let mut loop_helper = LoopHelper::builder() .report_interval_s(0.5) // report every half a second .build_with_target_rate(250.0); // limit to 250 FPS if possible let mut current_fps = None; loop { let delta = loop_helper.loop_start(); // or .loop_start_s() for f64 seconds // compute_something(delta); if let Some(fps) = loop_helper.report_rate() { current_fps = Some(fps.round()); } // render_fps(current_fps); loop_helper.loop_sleep(); // sleeps to acheive a 250 FPS rate }
Implementations
impl LoopHelper[src]
pub fn builder() -> LoopHelperBuilder[src]
Returns a LoopHelperBuilder with which to build a
LoopHelper.
pub fn loop_start(&mut self) -> Duration[src]
Notifies the helper that a new loop has begun.
Returns the delta, the duration since the last call to loop_start or loop_start_s.
pub fn loop_start_s(&mut self) -> Seconds[src]
Notifies the helper that a new loop has begun.
Returns the delta, the seconds since the last call to loop_start or loop_start_s.
pub fn loop_sleep(&mut self)[src]
Generally called at the end of a loop to sleep until the desired delta (configured with
build_with_target_rate)
has elapsed. Uses a SpinSleeper to sleep the thread to provide
improved accuracy. If the delta has already elapsed this method returns immediately.
pub fn loop_sleep_no_spin(&mut self)[src]
Generally called at the end of a loop to sleep until the desired delta (configured with
build_with_target_rate)
has elapsed. Does not use a SpinSleeper, instead directly
calls thread::sleep and will never spin. This is less accurate than
loop_sleep but less CPU intensive.
pub fn report_rate(&mut self) -> Option<RatePerSecond>[src]
Returns the mean rate per second recorded since the last report. Returns None if
the last report was within the configured report_interval.
pub fn set_target_rate<R: Into<RatePerSecond>>(&mut self, target_rate: R)[src]
Changes the target loop rate
pub fn target_rate(&self) -> RatePerSecond[src]
Returns the current target loop rate
Trait Implementations
impl Clone for LoopHelper[src]
fn clone(&self) -> LoopHelper[src]
pub fn clone_from(&mut self, source: &Self)1.0.0[src]
impl Debug for LoopHelper[src]
impl Eq for LoopHelper[src]
impl PartialEq<LoopHelper> for LoopHelper[src]
fn eq(&self, other: &LoopHelper) -> bool[src]
fn ne(&self, other: &LoopHelper) -> bool[src]
impl StructuralEq for LoopHelper[src]
impl StructuralPartialEq for LoopHelper[src]
Auto Trait Implementations
impl RefUnwindSafe for LoopHelper
impl Send for LoopHelper
impl Sync for LoopHelper
impl Unpin for LoopHelper
impl UnwindSafe for LoopHelper
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,