pub struct Timer { /* private fields */ }
Expand description
A timer event source
When registered to the event loop, it will trigger an event once its deadline is reached.
If the deadline is in the past relative to the moment of its insertion in the event loop,
the TImer
will trigger an event as soon as the event loop is dispatched.
Implementations§
Source§impl Timer
impl Timer
Sourcepub fn immediate() -> Timer
pub fn immediate() -> Timer
Create a timer that will fire immediately when inserted in the event loop
Sourcepub fn from_duration(duration: Duration) -> Timer
pub fn from_duration(duration: Duration) -> Timer
Create a timer that will fire after a given duration from now
Sourcepub fn from_deadline(deadline: Instant) -> Timer
pub fn from_deadline(deadline: Instant) -> Timer
Create a timer that will fire at a given instant
Sourcepub fn set_deadline(&mut self, deadline: Instant)
pub fn set_deadline(&mut self, deadline: Instant)
Changes the deadline of this timer to an Instant
If the Timer
is currently registered in the event loop, it needs to be
re-registered for this change to take effect.
Sourcepub fn set_duration(&mut self, duration: Duration)
pub fn set_duration(&mut self, duration: Duration)
Changes the deadline of this timer to a Duration
from now
If the Timer
is currently registered in the event loop, it needs to be
re-registered for this change to take effect.
Sourcepub fn current_deadline(&self) -> Option<Instant>
pub fn current_deadline(&self) -> Option<Instant>
Get the current deadline of this Timer
Returns None
if the timer has overflowed.
Trait Implementations§
Source§impl EventSource for Timer
impl EventSource for Timer
Source§type Ret = TimeoutAction
type Ret = TimeoutAction
Source§type Error = Error
type Error = Error
process_events()
(not the user callback!).Source§fn process_events<F>(
&mut self,
_: Readiness,
token: Token,
callback: F,
) -> Result<PostAction, <Timer as EventSource>::Error>where
F: FnMut(<Timer as EventSource>::Event, &mut <Timer as EventSource>::Metadata) -> <Timer as EventSource>::Ret,
fn process_events<F>(
&mut self,
_: Readiness,
token: Token,
callback: F,
) -> Result<PostAction, <Timer as EventSource>::Error>where
F: FnMut(<Timer as EventSource>::Event, &mut <Timer as EventSource>::Metadata) -> <Timer as EventSource>::Ret,
Source§fn register(
&mut self,
poll: &mut Poll,
token_factory: &mut TokenFactory,
) -> Result<(), Error>
fn register( &mut self, poll: &mut Poll, token_factory: &mut TokenFactory, ) -> Result<(), Error>
Source§fn reregister(
&mut self,
poll: &mut Poll,
token_factory: &mut TokenFactory,
) -> Result<(), Error>
fn reregister( &mut self, poll: &mut Poll, token_factory: &mut TokenFactory, ) -> Result<(), Error>
Source§fn unregister(&mut self, poll: &mut Poll) -> Result<(), Error>
fn unregister(&mut self, poll: &mut Poll) -> Result<(), Error>
Source§const NEEDS_EXTRA_LIFECYCLE_EVENTS: bool = false
const NEEDS_EXTRA_LIFECYCLE_EVENTS: bool = false
EventSource::before_sleep
and EventSource::before_handle_events
notifications. These are opt-in because
they require more expensive checks, and almost all sources will not need these notificationsSource§fn before_sleep(&mut self) -> Result<Option<(Readiness, Token)>, Error>
fn before_sleep(&mut self) -> Result<Option<(Readiness, Token)>, Error>
poll
is about to begin Read moreSource§fn before_handle_events(&mut self, events: EventIterator<'_>)
fn before_handle_events(&mut self, events: EventIterator<'_>)
EventSource::process_events
will
be called with the given events for this source. The iterator may be empty,
which indicates that no events were generated for this source Read moreAuto Trait Implementations§
impl Freeze for Timer
impl !RefUnwindSafe for Timer
impl !Send for Timer
impl !Sync for Timer
impl Unpin for Timer
impl !UnwindSafe for Timer
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more