Sha256: 1f77d42023e544b4b32ccadf0592c9e813083ba97f6ba781935d3f889ffadc2a

Contents?: true

Size: 1.55 KB

Versions: 12

Compression:

Stored size: 1.55 KB

Contents

//! Platform-specific extensions to [`web-time`](crate) for the Web platform.

#![allow(clippy::absolute_paths)]

use std::time::SystemTime as StdSystemTime;

use crate::SystemTime;

/// Web-specific extension to [`web_time::SystemTime`](crate::SystemTime).
pub trait SystemTimeExt {
	/// Convert [`web_time::SystemTime`](crate::SystemTime) to
	/// [`std::time::SystemTime`].
	///
	/// # Note
	///
	/// This might give a misleading impression of compatibility!
	///
	/// Considering this functionality will probably be used to interact with
	/// incompatible APIs of other dependencies, care should be taken that the
	/// dependency in question doesn't call [`std::time::SystemTime::now()`]
	/// internally, which would panic.
	fn to_std(self) -> std::time::SystemTime;

	/// Convert [`std::time::SystemTime`] to
	/// [`web_time::SystemTime`](crate::SystemTime).
	///
	/// # Note
	///
	/// This might give a misleading impression of compatibility!
	///
	/// Considering this functionality will probably be used to interact with
	/// incompatible APIs of other dependencies, care should be taken that the
	/// dependency in question doesn't call [`std::time::SystemTime::now()`]
	/// internally, which would panic.
	fn from_std(time: std::time::SystemTime) -> SystemTime;
}

impl SystemTimeExt for SystemTime {
	fn to_std(self) -> std::time::SystemTime {
		StdSystemTime::UNIX_EPOCH + self.0
	}

	fn from_std(time: std::time::SystemTime) -> SystemTime {
		Self::UNIX_EPOCH
			+ time
				.duration_since(StdSystemTime::UNIX_EPOCH)
				.expect("found `SystemTime` earlier then unix epoch")
	}
}

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/web-time-1.1.0/src/web.rs
wasmtime-28.0.0 ./ext/cargo-vendor/web-time-1.1.0/src/web.rs
wasmtime-27.0.0 ./ext/cargo-vendor/web-time-1.1.0/src/web.rs
wasmtime-26.0.0 ./ext/cargo-vendor/web-time-1.1.0/src/web.rs
wasmtime-25.0.2 ./ext/cargo-vendor/web-time-1.1.0/src/web.rs
wasmtime-25.0.1 ./ext/cargo-vendor/web-time-1.1.0/src/web.rs
wasmtime-25.0.0 ./ext/cargo-vendor/web-time-1.1.0/src/web.rs
wasmtime-24.0.0 ./ext/cargo-vendor/web-time-1.1.0/src/web.rs
wasmtime-23.0.2 ./ext/cargo-vendor/web-time-1.1.0/src/web.rs
wasmtime-22.0.0 ./ext/cargo-vendor/web-time-1.1.0/src/web.rs
wasmtime-21.0.1 ./ext/cargo-vendor/web-time-1.1.0/src/web.rs
wasmtime-20.0.2 ./ext/cargo-vendor/web-time-1.1.0/src/web.rs