Struct AutoDropTimer

Source
pub struct AutoDropTimer(/* private fields */);

Implementations§

Source§

impl AutoDropTimer

Source

pub fn from_timer(t: Timer) -> Self

Takes over the underlying timer and returns an instance of AutoDropTimer, encapsulating the Timer.

After calling this function, the timer t is moved into the AutoDropTimer.

§Parameters
  • t: The timer instance to be encapsulated.
§Returns

Returns the AutoDropTimer instance.

Source

pub fn new<F>( clk: Clock, duration: Duration, f: F, name: String, ) -> AnyResult<Self>
where F: FnOnce() + Send + Sync + 'static,

Creates an instance of AutoDropTimer on the clock indicated by the clk parameter.

§Arguments
  • clk: The clock instance on which to create the timer.
  • duration: Specifies the expiration duration of the timer.
  • f: Callback function invoked after the timer expires.
  • name: Name of the timer, used for logging purposes.
§Returns

Returns Ok(AutoDropTimer) if successful, or an error if creation fails.

Source

pub fn cancel(&mut self) -> AnyResult<()>

Cancels the timer before it expires.

Returns Ok(()) if it is successfully canceled, or an error if the timer has already expired. Applications should handle the race condition where a timer may expire after cancel is invoked.

§Returns

Returns Ok(()) if the timer is successfully canceled, or an error otherwise.

Source

pub fn take(&mut self) -> Option<Timer>

Extracts the Timer from the AutoDropTimer.

Applications need to handle canceling the timer when the Timer instance is dropped after calling this function.

§Returns

Returns the Timer if it exists, or None if it has been canceled.

Source

pub fn expired(&mut self)

Informs the AutoDropTimer to perform cleanup when the timer expires.

This function is primarily for performance considerations; functionally, it does not affect whether calling it or not on expiry.

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.