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>>
impl<'a> CallbackTimer<Box<dyn FnMut() + 'a>>
Sourcepub fn new<F>(time: Duration, f: F) -> Selfwhere
F: FnMut() + 'a,
pub fn new<F>(time: Duration, f: F) -> Selfwhere
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(),
impl<F> CallbackTimer<F>where
F: FnMut(),
Sourcepub fn new_unboxed(time: Duration, f: F) -> Self
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>
impl<F> Debug for CallbackTimer<F>
Source§impl<F> Timer for CallbackTimer<F>where
F: FnMut(),
impl<F> Timer for CallbackTimer<F>where
F: FnMut(),
Source§fn time_left(&mut self, idle_time: Duration) -> Result<Option<Duration>>
fn time_left(&mut self, idle_time: Duration) -> Result<Option<Duration>>
Return the time left based on the relative idle time
Source§fn disabled(&mut self) -> bool
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>
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<()>
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<()>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more