Struct CallbackTimer

Source
pub struct CallbackTimer<F>
where F: FnMut(),
{ pub disabled: bool, /* private fields */ }
Expand description

A timer that lets you easily execute a rust callback on activation

Fields§

§disabled: bool

Whether or not to disable this timer

Implementations§

Source§

impl<'a> CallbackTimer<Box<dyn FnMut() + 'a>>

Source

pub fn new<F>(time: Duration, f: F) -> Self
where F: FnMut() + 'a,

Create a new instance, which boxes the closure to a dynamic type. Use new_unboxed to use static dispatch, although keep in mind this will potentially make you unable to register more than one type of callback timer due to its static type.

Source§

impl<F> CallbackTimer<F>
where F: FnMut(),

Source

pub fn new_unboxed(time: Duration, f: F) -> Self

Create a new unboxed instance. Due to it’s static type, only one type can be used. This means that registering 2 timers with 2 different callbacks will conflict. An easy way to bypass this is using the new function, which behind the scenes just wraps the callback in a Box.

TL;DR: Don’t use this unless you’re planning on using another means of dynamic dispatch (an enum?) or if you’re a masochist.

Trait Implementations§

Source§

impl<F> Debug for CallbackTimer<F>
where F: FnMut() + Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<F> Timer for CallbackTimer<F>
where F: FnMut(),

Source§

fn time_left(&mut self, idle_time: Duration) -> Result<Option<Duration>>

Return the time left based on the relative idle time
Source§

fn activate(&mut self) -> Result<()>

Called when the timer was activated
Source§

fn disabled(&mut self) -> bool

Return true if the timer is disabled and should be skipped. Changes to this value are reflected - you may enable a timer that was previously disabled, and xidlehook will call it as soon as the timer is passed - or immediately if the timer has already passed.
Source§

fn abort_urgency(&self) -> Option<Duration>

How urgent this timer wants to be notified on abort (when the user is no longer idle). Return as slow of a duration as you think is acceptable to be nice to the CPU - preferrably return None which basically means infinity.
Source§

fn abort(&mut self) -> Result<()>

Called when the timer was aborted early - such as when the user moves their mouse or otherwise stops being idle.
Source§

fn deactivate(&mut self) -> Result<()>

Called when another timer was activated after this one

Auto Trait Implementations§

§

impl<F> Freeze for CallbackTimer<F>
where F: Freeze,

§

impl<F> RefUnwindSafe for CallbackTimer<F>
where F: RefUnwindSafe,

§

impl<F> Send for CallbackTimer<F>
where F: Send,

§

impl<F> Sync for CallbackTimer<F>
where F: Sync,

§

impl<F> Unpin for CallbackTimer<F>
where F: Unpin,

§

impl<F> UnwindSafe for CallbackTimer<F>
where F: UnwindSafe,

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.