Struct Timer

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

Posix timer wrapper

Implementations§

Source§

impl Timer

Source

pub const unsafe fn uninit() -> Self

Creates new uninitialized instance.

In order to use it one must call init.

Source

pub fn is_init(&self) -> bool

Returns whether timer is initialized

Source

pub fn init(&self, cb: Callback) -> bool

Performs timer initialization

cb pointer to function to invoke when timer expires.

Returns whether timer has been initialized successfully or not.

If timer is already initialized does nothing, returning false.

Source

pub fn new(cb: Callback) -> Option<Self>

Creates new timer, invoking provided cb when timer expires.

On failure, returns None

Source

pub fn schedule_interval(&self, timeout: Duration, interval: Duration) -> bool

Schedules timer to alarm periodically with interval with initial alarm of timeout.

Note that if timer has been scheduled before, but hasn’t expire yet, behaviour is undefined (Callback may or may not be called). To prevent that user must cancel timer first.

Returns true if successfully set, otherwise on error returns false

Source

pub fn is_scheduled(&self) -> bool

Returns true if timer has been scheduled and still pending.

On Win/Mac it only returns whether timer has been scheduled, as there is no way to check whether timer is ongoing

Source

pub fn cancel(&self)

Cancels ongoing timer, if it was scheduled.

Source§

impl Timer

Source

pub const fn schedule(&self) -> Schedule<'_>

Creates new schedule

Source

pub fn schedule_once(&self, timeout: Duration) -> bool

Schedules timer to alarm once after timeout passes.

Note that if timer has been scheduled before, but hasn’t expire yet, it shall be cancelled. To prevent that user must cancel timer first.

Returns true if successfully set, otherwise on error returns false

Trait Implementations§

Source§

impl Drop for Timer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Timer

Source§

impl Sync for Timer

Auto Trait Implementations§

§

impl !Freeze for Timer

§

impl !RefUnwindSafe for Timer

§

impl Unpin for Timer

§

impl UnwindSafe for Timer

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.