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:
- Consistency. With this approach, you don’t have to remember
which type uses
getand which usesnow. - 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 appropriateweb_time_compat::Instanttype instead.
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl InstantExt for Instant
Available on not (WebAssembly and
target_os=unknown).