Struct Interval

Source
pub struct Interval { /* private fields */ }
Expand description

Interval returned by interval and interval_at.

Implementations§

Source§

impl Interval

Source

pub fn tick(&mut self) -> Instant

Use SpinSleeper::sleep to sleep until the next scheduled tick.

If the tick is in the past will return without sleeping computing the next tick based on the configured MissedTickBehavior.

Returns the tick time.

Source

pub fn tick_no_spin(&mut self) -> Instant

Use spin_sleep::native_sleep to sleep until the next scheduled tick. Does not spin.

If the tick is in the past will return without sleeping computing the next tick based on the configured MissedTickBehavior.

Returns the tick time.

Source

pub fn reset(&mut self)

Resets the scheduled next tick to one period after the current time.

Source

pub fn missed_tick_behavior(&self) -> MissedTickBehavior

Returns the MissedTickBehavior strategy currently being used.

§Example
use spin_sleep_util::{interval, MissedTickBehavior};

let i = interval(Duration::from_millis(20));
assert_eq!(i.missed_tick_behavior(), MissedTickBehavior::Skip);
Source

pub fn period(&self) -> Duration

Returns the period of the interval.

§Example
use spin_sleep_util::interval;

let i = interval(Duration::from_millis(20));
assert_eq!(i.period(), Duration::from_millis(20));
Source

pub fn set_period(&mut self, period: Duration)

Sets a new period.

Does not affect the existing scheduled next tick.

§Example
use spin_sleep_util::interval;

let mut i = interval(Duration::from_millis(20));
i.set_period(Duration::from_secs(1));
assert_eq!(i.period(), Duration::from_secs(1));
Source

pub fn set_missed_tick_behavior(&mut self, behavior: MissedTickBehavior)

Sets the MissedTickBehavior strategy that should be used.

§Example
use spin_sleep_util::{interval, MissedTickBehavior};

let mut i = interval(Duration::from_millis(20));
i.set_missed_tick_behavior(MissedTickBehavior::Burst);
assert_eq!(i.missed_tick_behavior(), MissedTickBehavior::Burst);
Source

pub fn with_missed_tick_behavior(self, behavior: MissedTickBehavior) -> Self

Returns Self with the specified MissedTickBehavior strategy.

§Example
use spin_sleep_util::{interval, MissedTickBehavior};

let i =
    interval(Duration::from_millis(20)).with_missed_tick_behavior(MissedTickBehavior::Burst);
assert_eq!(i.missed_tick_behavior(), MissedTickBehavior::Burst);
Source

pub fn spin_sleeper(&self) -> SpinSleeper

Returns the configured SpinSleeper.

§Example
use spin_sleep::SpinSleeper;
use spin_sleep_util::interval;

let i = interval(Duration::from_millis(20));
assert_eq!(i.spin_sleeper(), SpinSleeper::default());
Source

pub fn set_spin_sleeper(&mut self, sleeper: SpinSleeper)

Sets the SpinSleeper used for accurate sleeping.

§Example
use spin_sleep_util::interval;

let mut i = interval(Duration::from_millis(20));
i.set_spin_sleeper(custom_sleeper);
assert_eq!(i.spin_sleeper(), custom_sleeper);
Source

pub fn with_spin_sleeper(self, sleeper: SpinSleeper) -> Self

Returns Self with the specified SpinSleeper.

§Example
use spin_sleep_util::interval;

let i = interval(Duration::from_millis(20)).with_spin_sleeper(custom_sleeper);
assert_eq!(i.spin_sleeper(), custom_sleeper);

Trait Implementations§

Source§

impl Debug for Interval

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.