Skip to main content

InstantExt

Trait InstantExt 

Source
pub trait InstantExt: Sealed {
    // Required method
    fn get() -> Instant;
}
Expand description

Extension trait for Instant.

This trait adds a get method which works like now, so we can make sure we aren’t calling std::time::Instant::now onwasm32-unknown-unknown environments.

§Design note

Since we already replace the std::time::Instant type with web_time::Instant in this crate, why do we also provide an extension trait to rename its “now” method?

We do so for two reasons:

  1. Consistency. With this approach, you don’t have to remember which type uses get and which uses now.
  2. Enforcement. This approach makes it possible to use Clippy to disallow std::time::Instant::now() unconditionally, to make sure that you don’t forget to use the appropriate web_time_compat::Instant type instead.

Required Methods§

Source

fn get() -> Instant

Return the current time.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§